React Native Requires Chilkat v11.0.0+
React Native
Use Base64 RSA Key to Encrypt
See more RSA Examples
Loads a Base64 RSA key and uses it to encrypt a string, returning the result in base64.Chilkat React Native Downloads
import { PublicKey, Rsa } from '@chilkat/react-native'
function chilkatExample() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const pubkey = new PublicKey();
try {
pubkey.loadBase64('MIICdgIBADA ... A9PXLk+j5A==');
} catch {
console.log(pubkey.lastErrorText);
return;
}
const rsa = new Rsa();
try {
rsa.usePublicKey(pubkey);
} catch {
console.log(rsa.lastErrorText);
return;
}
rsa.encodingMode = 'base64';
const encryptedStr = rsa.encryptStringENC('12345678', false);
console.log(encryptedStr);
}