当我搜索 RSACypthyServiceProvider 时,我在 MSDN 上找到了以下代码示例。在评论的帮助下,我无法理解代码的某些部分。
什么是模数和指数?
什么是IV?
为什么他们使用 RijndaelManagedclass 进行非对称加密?根据我的搜索,RSACryptoServiceProvider 提供了非对称加密功能,它会在我们创建对象时自动创建私钥和公钥。那么 RijndaelManaged 实例的目的是什么?
任何人都可以解释一下吗?
代码示例:
class Class1
{
static void Main()
{
//Initialize the byte arrays to the public key information.
byte[] PublicKey = {Somethink in byte}
byte[] Exponent = {1,0,1};
//Create values to store encrypted symmetric keys.
byte[] EncryptedSymmetricKey;
byte[] EncryptedSymmetricIV;
//Create a new instance of the RSACryptoServiceProvider class.
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
//Create a new instance of the RSAParameters structure.
RSAParameters RSAKeyInfo = new RSAParameters();
//Set RSAKeyInfo to the public key values.
RSAKeyInfo.Modulus = PublicKey;
RSAKeyInfo.Exponent = Exponent;
//Import key parameters into RSA.
RSA.ImportParameters(RSAKeyInfo);
//Create a new instance of the RijndaelManaged class.
RijndaelManaged RM = new RijndaelManaged();
//Encrypt the symmetric key and IV.
EncryptedSymmetricKey = RSA.Encrypt(RM.Key, false);
EncryptedSymmetricIV = RSA.Encrypt(RM.IV, false);
}
}