React Native Requires Chilkat v11.0.0+
React Native
RSA Sign Using Private Key from .pfx/.p12 to Base64 Signature
See more RSA Examples
Demonstrates how to RSA sign something using a private key loaded from a .pfx/.p12. The RSA signature is returned in Base64 encoded format.Chilkat React Native Downloads
import { Pfx, PrivateKey, Rsa } from '@chilkat/react-native'
function chilkatExample() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const rsa = new Rsa();
// Load the .pfx/.p12
const pfx = new Pfx();
try {
pfx.loadPfxFile('qa_data/pfx/myKey.p12', 'myPassword');
} catch {
console.log(pfx.lastErrorText);
return;
}
// Get the default private key.
const privKey = new PrivateKey();
try {
pfx.privateKeyAt(0, privKey);
} catch {
console.log(pfx.lastErrorText);
return;
}
// Import the private key into the RSA component:
try {
rsa.usePrivateKey(privKey);
} catch {
console.log(rsa.lastErrorText);
return;
}
// Get the signature in base64
rsa.encodingMode = 'base64';
const strData = 'This is the string to be signed.';
// Sign the string using the sha256 hash algorithm.
// Other valid choices are "sha384", "sha512", "sha-1", "md2" and "md5".
const base64Sig = rsa.signStringENC(strData, 'sha256');
console.log(base64Sig);
console.log('Success!');
}