generatePrivateKeysAsync method
Generate private keys.
Returns a SealdGeneratedPrivateKeys instance that can be used with synchronous methods.
Implementation
Future<SealdGeneratedPrivateKeys> generatePrivateKeysAsync() async {
if (Platform.isMacOS || Platform.isIOS || Platform.isAndroid) {
BackgroundIsolateBinaryMessenger.ensureInitialized(_rootIsolateToken);
const MethodChannel channel =
MethodChannel('io.seald.seald_sdk_flutter.native_rsa_key_generator');
Map<Object?, Object?> res =
await channel.invokeMethod('generateRSAKeys', {'size': _keySize});
Object? encryptionKey = res['encryptionKey'];
Object? signingKey = res['signingKey'];
Object? format = res['format'];
if (encryptionKey is String && signingKey is String && format is String) {
if (format == 'PKCS8') {
return SealdGeneratedPrivateKeys(encryptionKey, signingKey);
} else if (format == 'PKCS1DER') {
return SealdGeneratedPrivateKeys(
_pkcs1DerToPkcs8(encryptionKey), _pkcs1DerToPkcs8(signingKey));
} else {
throw SealdException(code: "INVALID_GENERATED_KEY_FORMAT");
}
} else {
throw SealdException(code: "INVALID_GENERATED_KEYS");
}
} else {
return SealdGeneratedPrivateKeys(
await compute((_) => _generatePrivateKey(4096), null),
await compute((_) => _generatePrivateKey(4096), null));
}
}