2014-11-24 155 views
-1

这很奇怪。我有这个方法来加密的字符串:System.Security.Cryptography.CryptographicException:对象已存在

[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Assert, Unrestricted = true)] 
public static string Encrypt(this string stringToEncrypt, string key) { 
    var cspp = new CspParameters { 
     KeyContainerName = key, 
     Flags = CspProviderFlags.UseMachineKeyStore 
    }; 
    var rsa = new RSACryptoServiceProvider(cspp) { 
     PersistKeyInCsp = true 
    }; 
    var bytes = rsa.Encrypt(System.Text.Encoding.UTF8.GetBytes(stringToEncrypt), true); 
    return BitConverter.ToString(bytes); 
} 

这是我的客户:

private const string EncryptionKey = "pezhman"; 

static Random random = new Random(); 
public static int CreateSalt() { 
    return random.Next(1000, 9999); 
} 

public void EncryptSomething() { 
    var salt = CreateSalt(); 
    var plainText = salt + "," + DateTime.Now; 
    var encryptionSaltKey = EncryptionKey + DateTime.Now.Date; 
    // here im calling encryptor: 
    var encryptedValue = plainText.Encrypt(encryptionSaltKey); 
} 

我在ASP.NET MVC 4应用程序中使用此。它工作完美;但突然停止工作。其实,在当地,我没有问题,它的工作。但是,当我发表我的代码到服务器,我得到这个错误:

System.Security.Cryptography.CryptographicException: Object already exists.

你有任何想法,这里发生了什么?我知道我可以grant access to the key to everyone我在问什么是在服务器上发生了什么?什么改变了?什么样的改变会导致这个问题?

+0

你已经看过这个吗? http://stackoverflow.com/questions/11430966/system-security-cryptography-cryptographicexception-object-already-exist/11445029#11445029 – rodrigogq 2014-11-24 15:51:28

+0

@rodrigogq是的我已经在我的问题中提到过。我想知道服务器发生了什么?什么样的改变会导致这个问题? – 2014-11-24 15:54:12

+0

对不起,我以前没有链接过链接。在此提供一些背景知识:你刚刚改变了你的应用程序吗?任何Windows更新安装,什么IIS?您的AppPool使用任何特定用户还是默认值?有人改变了吗? – rodrigogq 2014-11-24 16:03:54

回答

1

What I'm asking is, what just happened at the server? What is changed? What kind of changes can cause the problem?

一种可能性是最近发布的Windows secuirty更新MS14-059,虽然我不能解释你所得到的错误消息。

基本上,该更新完全卸载MVC 4.0.0.0并将其替换为您的服务器上的4.0.0.1,并且它已经导致许多破损构建人员的悲痛。由于加密可能取决于DLL的版本号非常特定的内容,因此您可能需要从此处开始。您可以通过在未安装上述安全修补程序的计算机上测试您的应用程序来验证或反驳该理论,以查看它是否再次开始工作。

+0

我更换了钥匙,并得到解决。但关于服务器,我认为你是对的。在发生这种情况之前,服务器大约在3到4分钟内无法访问。他们可能已经安装了(或类似的)更新。不幸的是我的托管公司不负责。每件事都是猜测。但多亏了帮助。 +1 – 2014-11-25 06:46:04

相关问题