// 加载公钥
RsaKeyParameters pubkey;
using (var sr = new StreamReader(ConfigurationManager.AppSettings["PubKey"]))
{
var pemReader = new Org.BouncyCastle.OpenSsl.PemReader(sr);
pubkey = (RsaKeyParameters)pemReader.ReadObject();
}
// 初始化cipher
var cipher = (BufferedAsymmetricBlockCipher)CipherUtilities.GetCipher("RSA/ECB/OAEPWITHSHA-1ANDMGF1PADDING");
cipher.Init(true, pubkey);
// 加密message
var message = Encoding.UTF8.GetBytes(EncryptString);
var output = EncryptUtil.Encrypt(message, cipher);
R = Convert.ToBase64String(output);
1