framewrok RSA SHA512加密

 public static string EncryptPassphrase(string publicKey, string passphrase)
 {
     byte[] publicKeyBytes = Convert.FromBase64String(publicKey);

     // 创建RSA公钥参数对象
     RsaKeyParameters publicKeyParams = (RsaKeyParameters)PublicKeyFactory.CreateKey(publicKeyBytes);

     // 创建RSA引擎实例
     var engine = new OaepEncoding(new RsaEngine(), new Sha512Digest());

     // 初始化为加密模式
     engine.Init(true, publicKeyParams);

     // 要加密的数据
     byte[] bytesToEncrypt = Encoding.UTF8.GetBytes(passphrase);

     // 加密数据
     byte[] encryptedBytes = engine.ProcessBlock(bytesToEncrypt, 0, bytesToEncrypt.Length);

     // 加密后的数据(转为Base64字符串以便显示)
     string encryptedText = Convert.ToBase64String(encryptedBytes);
     return encryptedText;
 }

 

posted @ 2024-06-20 09:38  烟台西炮台  阅读(2)  评论(0编辑  收藏  举报