React Native Requires Chilkat v11.0.0+
React Native
Verfies an RSA Signature
See more Apple Keychain Examples
Verifies an RSA signature against the original data.Chilkat React Native Downloads
import { BinData, PublicKey, Rsa } from '@chilkat/react-native'
function chilkatExample() {
// The following data was signed by the following example:
// RSA Sign using a Private Key on a USB Token or Smartcard
const bd = new BinData();
for (let i = 0; i <= 100; i++) {
bd.appendEncoded('000102030405060708090A0B0C0D0E0F', 'hex');
}
// Load the signature
const bdSig = new BinData();
try {
bdSig.loadFile('rsaSignatures/test1.sig');
} catch {
console.log('Failed to load the RSA signature');
return;
}
// Get the public key to be used for signature verification.
const pubKey = new PublicKey();
try {
pubKey.loadFromFile('rsaKeys/chilkat-rsa-2048.pem');
} catch {
console.log(pubKey.lastErrorText);
return;
}
const rsa = new Rsa();
try {
rsa.usePublicKey(pubKey);
} catch {
console.log(rsa.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);
console.log('Signature valid.');
} catch {
console.log(rsa.lastErrorText);
console.log('Signature invalid.');
}
}