newKeyPair method
Generates a new KeyPair
that can be used with this algorithm.
Example
In this example, we use X25519
:
import 'package:cryptography/cryptography.dart';
Future<void> main() async {
final algorithm = X25519();
final keyPair = await algorithm.newKeyPair();
}
Implementation
@override
Future<EcKeyPair> newKeyPair() async {
if (isSupportedPlatform) {
final result = await invokeMethod(
'Ecdh.newKeyPair',
{
if (isAndroid) 'androidProvider': androidCryptoProvider,
'curve': _curveName,
},
);
final der = result['der'] as Uint8List?;
if (der != null) {
return EcKeyPairData.parseDer(
der,
type: keyPairType,
);
}
final d = result['d'] as Uint8List;
final x = result['x'] as Uint8List;
final y = result['y'] as Uint8List;
return EcKeyPairData(
d: d,
x: x,
y: y,
type: keyPairType,
);
}
final fallback = this.fallback;
if (fallback == null) {
throw UnsupportedError('Unsupported and no fallback implementation');
}
return await fallback.newKeyPair();
}