rsaDecrypt static method

String rsaDecrypt(
  1. String encryptedStr,
  2. String privateKeyStr
)

RSA加密算法解密,秘钥格式为pkcs8 encryptedStr密文,base64编码 privateKeyStr私钥

Implementation

static String rsaDecrypt(String encryptedStr, String privateKeyStr) {
  final parser = RSAKeyParser();
  String publicKeyString = _transformPem(privateKeyStr, isPublic: false);
  RSAPrivateKey privateKey = parser.parse(publicKeyString) as RSAPrivateKey;
  final encryptor = Encrypter(RSA(privateKey: privateKey));
  final encrypted = Encrypted.fromBase64(encryptedStr);
  final decrypted = encryptor.decrypt(encrypted);
  return decrypted;
}