sign method
Calculates signature for the message.
Implementation
@override
Future<Signature> sign(
List<int> data, {
required KeyPair keyPair,
}) async {
if (usePlugin) {
try {
final keyPairData = await keyPair.extract();
if (keyPairData is! RsaKeyPairData) {
throw ArgumentError.value(
keyPair,
'keyPair',
);
}
final result = await channel.invokeMethod(
'rsa_pss_sign',
{
'data': base64Encode(data),
'd': base64Encode(keyPairData.d),
'e': base64Encode(keyPairData.e),
'n': base64Encode(keyPairData.n),
'p': base64Encode(keyPairData.p),
'q': base64Encode(keyPairData.q),
},
);
if (result is! Map) {
throw StateError('Invalid output from plugin: $result');
}
final bytes = base64Decode(result['bytes'] as String);
return Signature(bytes,
publicKey: await keyPairData.extractPublicKey());
} catch (error) {
usePlugin = false;
}
}
return super.sign(data, keyPair: keyPair);
}