rsaEncode method

Future<String> rsaEncode({
  1. String pem = 'packages/ecp_global/assets/texts/pub.pem',
})

使用RSA算法对字符串进行加密 @param pem RSA公钥文件路径,默认为'packages/ecp_global/assets/texts/pub.pem' @return 加密后的字符串

Implementation

Future<String> rsaEncode(
    {String pem = 'packages/ecp_global/assets/texts/pub.pem'}) async {
  // 从指定路径加载RSA公钥字符串
  String str = await rootBundle.loadString(pem);
  // 解析加载的公钥字符串为RSA公钥对象
  dynamic publicKey = RSAKeyParser().parse(str);
  // 创建RSA加密器实例,使用解析的公钥
  final encryptor = Encrypter(RSA(publicKey: publicKey));
  // 使用RSA加密器加密当前字符串
  final encrypted = encryptor.encrypt(this);
  // 返回加密后字符串的Base64编码表示
  return encrypted.base64;
}