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

Duplicate openssl dgst -sha256 -sign private.pem -out sha256.sig in.dat

See more OpenSSL Examples

Demonstrates how to duplicate this OpenSSL command:
openssl dgst -sha256 -sign private.pem -out sha256.sig in.dat
The in.dat file can contain text or binary data of any type. The OpenSSL command does the following:
  1. Creates a SHA256 digest of the contents of the input file
  2. Signs the SHA256 digest using the private key.

Chilkat React Native Downloads

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

  // Load the private key from an PEM file:
  try {
    pkey.loadPemFile('private.pem');
  } catch {
    console.log(pkey.lastErrorText);
    return;
  }

  const rsa = new Rsa();

  // Import the private key into the RSA component:
  try {
    rsa.usePrivateKey(pkey);
  } catch {
    console.log(rsa.lastErrorText);
    return;
  }

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

  // Load the file to be signed.
  const bdFileData = new BinData();
  bdFileData.loadFile('in.dat');

  const bdSig = new BinData();
  try {
    rsa.signBd(bdFileData, 'sha256', bdSig);
  } catch {
    console.log(rsa.lastErrorText);
    return;
  }

  // Save the binary signature to a file.
  try {
    bdSig.writeFile('signature.sig');
  } catch {
    console.log('Failed to write signature.sig.');
    return;
  }

  console.log('Success.');
}