generateRSAKeyPair function

AsymmetricKeyPair<RSAPublicKey, RSAPrivateKey> generateRSAKeyPair(
  1. {int bitLength = 2048}
)

----------------------------------------------RSA公钥私钥----------------------------------------------------

Implementation

AsymmetricKeyPair<RSAPublicKey, RSAPrivateKey> generateRSAKeyPair({int bitLength = 2048}) {
  // Create an RSA key generator and initialize it
  final keyGen = RSAKeyGenerator()
    ..init(ParametersWithRandom(RSAKeyGeneratorParameters(BigInt.parse('65537'), bitLength, 64), _secureRandom));
  // Use the generator
  final pair = keyGen.generateKeyPair();
  // Cast the generated key pair into the RSA key types
  final myPublic = pair.publicKey as RSAPublicKey;
  final myPrivate = pair.privateKey as RSAPrivateKey;
  return AsymmetricKeyPair<RSAPublicKey, RSAPrivateKey>(myPublic, myPrivate);
}