newKeyPair method

  1. @override
Future<RsaKeyPair> newKeyPair({
  1. int modulusLength = RsaSsaPkcs1v15.defaultModulusLength,
  2. List<int> publicExponent = RsaSsaPkcs1v15.defaultPublicExponent,
})
override

Generates a new KeyPair for this algorithm.

You can pass key generation preferences by specifying options.

Implementation

@override
Future<RsaKeyPair> newKeyPair({
  int modulusLength = RsaSsaPkcs1v15.defaultModulusLength,
  List<int> publicExponent = RsaSsaPkcs1v15.defaultPublicExponent,
}) async {
  if (usePlugin) {
    try {
      final result = await channel.invokeMethod(
        'new_rsa_secret_key',
        {},
      );
      if (result is! Map) {
        throw StateError('Invalid output from plugin: $result');
      }
      final d = result['d'] as Uint8List;
      final e = result['e'] as Uint8List;
      final n = result['n'] as Uint8List;
      final p = result['p'] as Uint8List;
      final q = result['q'] as Uint8List;
      return RsaKeyPairData(
        d: d,
        e: e,
        n: n,
        p: p,
        q: q,
      );
    } catch (error) {
      usePlugin = false;
    }
  }
  return fallback.newKeyPair();
}