我有一个.NET 4.5 MVC应用程序,我正在尝试用RSACryptoServiceProvider
来加密一些消息。但是,当我尝试使用EncryptValue()
时,我得到一个NotSupportedException。这是我的代码:
RSACryptoServiceProvider RSA = GetKeyFromContainer(_CONTAINER_NAME);
byte[] byteEncrypted = RSA.EncryptValue(byteData); //Here is where I get the exception
GetKeyFromContainer方法(从the documentation复制):
/// <summary>
/// Gets the private from the container and generates a new public key
/// </summary>
/// <param name="ContainerName"></param>
/// <returns></returns>
private RSACryptoServiceProvider GetKeyFromContainer(string ContainerName)
{
// Create the CspParameters object and set the key container
// name used to store the RSA key pair.
CspParameters cp = new CspParameters();
cp.KeyContainerName = ContainerName;
// Create a new instance of RSACryptoServiceProvider that accesses
// the key container
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cp);
return rsa;
}
.NET 4.5不支持此方法吗?有没有替代方法?