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<SimpleKeyPair> newKeyPair() async {
if (!kIsWeb) {
if (isSupportedPlatform) {
final result = await invokeMethod('X25519.newKeyPair', {});
return SimpleKeyPairData(
result['privateKey'] as Uint8List,
publicKey: SimplePublicKey(
result['publicKey'] as Uint8List,
type: KeyPairType.x25519,
),
type: KeyPairType.x25519,
);
}
}
return await fallback.newKeyPair();
}