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

RSASSA-PSS Algorithm with SHA256 Hashing

See more RSA Examples

RSA encrypt a SHA256 hash with OAEP padding.

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 privkey = CkPrivateKey();

  // Load the private key object from a PEM file.
  // (To load from a PEM string, call LoadPem instead.)
  try {
    privkey.loadPemFile('somePath/myPrivateKey.pem');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final rsa = CkRsa();
  // Use RSA-PSS by setting PkcsPadding = false
  rsa.pkcsPadding = false;
  // Use SHA256
  rsa.oaepHash = 'SHA-256';

  rsa.usePrivateKey(privkey);

  // Generate a base64 signature.
  rsa.encodingMode = 'base64';

  final String sigStr;
  try {
    sigStr = rsa.signStringENC('String to be signed', 'SHA-256');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  print('Signature: $sigStr');
}