React Native Requires Chilkat v11.0.0+
React Native
RSA Sign using Base64 Private Key
See more RSA Examples
Signs a string using a non-encrypted RSA private key in base64 encoding. Returns the RSA signature as a base64 string.Chilkat React Native Downloads
import { BinData, PrivateKey, Rsa, StringBuilder } from '@chilkat/react-native'
function chilkatExample() {
// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const privKey = new PrivateKey();
const sbPem = new StringBuilder();
sbPem.appendLine('-----BEGIN RSA PRIVATE KEY-----', true);
sbPem.appendLine('MIIC .... j5A==', true);
sbPem.appendLine('-----END RSA PRIVATE KEY-----', true);
try {
privKey.loadPem(sbPem.getAsString());
} catch {
console.log(privKey.lastErrorText);
return;
}
const rsa = new Rsa();
try {
rsa.usePrivateKey(privKey);
} catch {
console.log(rsa.lastErrorText);
return;
}
const bd = new BinData();
bd.appendString('12345678', 'utf-8');
try {
rsa.signRawBd(bd);
} catch {
console.log(rsa.lastErrorText);
return;
}
// Get the base64 RSA signature.
console.log(bd.getEncoded('base64'));
try {
rsa.verifyRawBd(bd);
} catch {
console.log(rsa.lastErrorText);
return;
}
const strOriginal = bd.getString('utf-8');
console.log(strOriginal);
}