sign method
SSHEcdsaSignature
sign(
- Uint8List data
)
override
Implementation
@override
SSHEcdsaSignature sign(Uint8List data) {
late Digest hash;
late ECDomainParameters curve;
switch (curveId) {
case 'nistp256':
hash = SHA256Digest();
curve = ECCurve_secp256r1();
break;
case 'nistp384':
hash = SHA384Digest();
curve = ECCurve_secp384r1();
break;
case 'nistp521':
hash = SHA512Digest();
curve = ECCurve_secp521r1();
break;
default:
throw UnsupportedError('Unsupported curve: $curveId');
}
final signer = ECDSASigner(hash);
signer.init(
true,
ParametersWithRandom(
PrivateKeyParameter(ECPrivateKey(d, curve)),
FortunaRandom()..seed(KeyParameter(randomBytes(32))),
),
);
final signature = signer.generateSignature(data) as ECSignature;
return SSHEcdsaSignature('ecdsa-sha2-$curveId', signature.r, signature.s);
}