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

Duplicate openssl dgst -sha256 -verify pubKey.pem -signature signature.sig in.dat

See more OpenSSL Examples

Demonstrates how to duplicate this OpenSSL command:
openssl dgst -sha256 -verify pubKey.pem -signature signature.sig in.dat
The in.dat file contains the original data that was signed, and can contain text or binary data of any type. The above OpenSSL command does the following:
  1. Creates a SHA256 digest of the contents of the input file.
  2. Verifies the SHA256 digest using the public key.

Chilkat React Native Downloads

React Native
import { BinData, 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();

  // Load the public key from an PEM file:
  try {
    pubKey.loadFromFile('pubKey.pem');
  } catch {
    console.log(pubKey.lastErrorText);
    return;
  }

  // Load the data of the original file that was signed.
  const bdFileData = new BinData();
  bdFileData.loadFile('in.dat');

  // Load the signature.
  const bdSig = new BinData();
  bdSig.loadFile('signature.sig');

  const rsa = new Rsa();

  // Import the public key into the RSA component:
  try {
    rsa.usePublicKey(pubKey);
  } catch {
    console.log(rsa.lastErrorText);
    return;
  }

  // OpenSSL uses big-endian.
  rsa.littleEndian = false;

  try {
    rsa.verifyBd(bdFileData, 'sha256', bdSig);
  } catch {
    console.log(rsa.lastErrorText);
    console.log('The signature was invalid.');
    return;
  }

  console.log('The signature was verified.');
}