rsaDecrypt static method

String? rsaDecrypt(
  1. String publicKey,
  2. String data
)

rsa解密 publicKey rsa 公钥 data 需要解密的base64内容

Implementation

static String? rsaDecrypt(String publicKey, String data) {
  try {
    RSAPublicKey key = RSAKeyParser().parse(publicKey) as RSAPublicKey;

    AsymmetricBlockCipher cipher = PKCS1Encoding(RSAEngine());
    cipher.init(false, PublicKeyParameter<RSAPublicKey>(key));

    List<int> sourceBytes = base64Decode(data);
    var process = cipher.process(Uint8List.fromList(sourceBytes));

    return utf8.decode(process);
  } catch (e) {
    return null;
  }
}