Sample code for 30+ languages & platforms
React Native Requires Chilkat v11.0.0+

RSA Import Public Key from Certificate PEM

See more RSA Examples

Uses a certificate's public key for RSA encryption. The public key from the certificate .pem file is used.

Chilkat React Native Downloads

React Native
import { Cert, PublicKey, Rsa } from '@chilkat/react-native'

function chilkatExample() {
  const cert = new Cert();

  try {
    cert.loadFromFile('qa_data/pem/mf_public_rsa.pem');
  } catch {
    console.log(cert.lastErrorText);
    return;
  }

  const pubKey = new PublicKey();
  cert.getPublicKey(pubKey);

  const rsa = new Rsa();
  rsa.usePublicKey(pubKey);

  rsa.encodingMode = 'base64';
  const encryptedStr = rsa.encryptStringENC('hello', false);
  console.log(`encrypted string = ${encryptedStr}`);
}