Flutter的RSA加密(支持modules和exponent

import ‘dart:io’;

import ‘package:encrypt/encrypt.dart’;

import ‘package:flutter/services.dart’ show rootBundle;

import ‘package:pointycastle/asymmetric/api.dart’;

class EncryptTool {

  ///  加密

  static encryption(content) async {

    final parser = RSAKeyParser();

    String publicKeyString =

        await rootBundle.loadString(‘assets/rsa/public.pem’);

    print(‘$publicKeyString’); // 注意这一行的输出

    final mpublicKey = parser.parse(publicKeyString);

    var publicKey = RSAPublicKey(mpublicKey.modulus!, mpublicKey.exponent!);

    final encrypter = Encrypter(RSA(publicKey: publicKey));

    final res = encrypter.encrypt(content).base64;

    print(“encryption data:”);

    print(encryption);

    return res;

  }

}

Share