Sample code for 30+ languages & platforms
Dart 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 Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  // This example requires the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  final pubKey = CkPublicKey();

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

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

  // Load the signature.
  final bdSig = CkBinData();
  bdSig.loadFile('signature.sig');

  final rsa = CkRsa();

  // Import the public key into the RSA component:
  try {
    rsa.usePublicKey(pubKey);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

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

  try {
    rsa.verifyBd(bdFileData, 'sha256', bdSig);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    print('The signature was invalid.');
    return;
  }

  print('The signature was verified.');
}