Dart Requires Chilkat v11.0.0+
Dart
Verfies an RSA Signature
See more Apple Keychain Examples
Verifies an RSA signature against the original data.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// The following data was signed by the following example:
// RSA Sign using a Private Key on a USB Token or Smartcard
final bd = CkBinData();
for (var i = 0; i <= 100; i++) {
bd.appendEncoded('000102030405060708090A0B0C0D0E0F', 'hex');
}
// Load the signature
final bdSig = CkBinData();
try {
bdSig.loadFile('rsaSignatures/test1.sig');
} on ChilkatException {
print('Failed to load the RSA signature');
return;
}
// Get the public key to be used for signature verification.
final pubKey = CkPublicKey();
try {
pubKey.loadFromFile('rsaKeys/chilkat-rsa-2048.pem');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
final rsa = CkRsa();
try {
rsa.usePublicKey(pubKey);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Verify the hash of the data against the signature.
// We pass in the original data. Internally, the hash is generated
// and used to validate the signature.
// Validating the RSA signature means two things:
// (1) the original data is exactly what was signed, and
// (2) it was signed by the owner of the RSA private key.
try {
rsa.verifyBd(bd, 'sha256', bdSig);
print('Signature valid.');
} on ChilkatException catch (e) {
print(e.lastErrorText);
print('Signature invalid.');
}
}