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; }
标签:engine,加密,string,RSA,framewrok,new,byte,SHA512 From: https://www.cnblogs.com/yantaixuchao/p/18258073