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; }