账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    C# RSA 证书私钥加密 多次加密结果不一致?
    9
    0
    string cert = @"D:\XXXXX\private2312.pfx"; X509Certificate2 prvcrt = new X509Certificate2(cert, "123456", X509KeyStorageFlags.Exportable); RSACryptoServiceProvider pubkey = (RSACryptoServiceProvider)prvcrt.PublicKey.Key; RSACryptoServiceProvider prvkey = (RSACryptoServiceProvider)prvcrt.PrivateKey; var str_1 = "asdfghjklqwertyu"; byte[] dataToEncrypt_1 = ByteConverter.GetBytes(str_1); encryptedData = RSAEncrypt(dataToEncrypt_1, prvkey.ExportParameters(true), false); var encryptedData2 = RSAEncrypt(dataToEncrypt_1, prvkey.ExportParameters(true), false); var data_1 = Convert.ToBase64String(encryptedData); var data_2 = Convert.ToBase64String(encryptedData2); static public byte[] RSAEncrypt(byte[] DataToEncrypt, RSAParameters RSAKeyInfo, bool DoOAEPPadding) { try { byte[] encryptedData; //Create a new instance of RSACryptoServiceProvider. using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider()) { //Import the RSA Key information. This only needs //toinclude the public key information. RSA.ImportParameters(RSAKeyInfo); //Encrypt the passed byte array and specify OAEP padding. //OAEP padding is only available on Microsoft Windows XP or //later. encryptedData = RSA.Encrypt(DataToEncrypt, DoOAEPPadding); } return encryptedData; } //Catch and display a CryptographicException //to the console. catch (CryptographicException e) { Console.WriteLine(e.Message); return null; } }
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答