Quickstart

This guide will get you all set up and ready to use the Skiff Crypto Library.

Installation

Inside your project, run either of the commands below to add Skiff UI:

# Install Skiff UI with npm
npm install @skiff-org/skiff-crypto --save
# Install Skiff UI with yarn
yarn add @skiff-org/skiff-crypto

Using Skiff Crypto inside your app

Integrate Skiff's cryptography library into your project easily, as shown below:

  import * as skiffCrypto from '@skiff-org/skiff-crypto';

  // Asymmetric encryption example
  const plaintext = "Hello, skiff-crypto!";
  const keypair = skiffCrypto.generatePublicPrivateKeyPair();
  const encrypted = skiffCrypto.stringEncryptAsymmetric(keypair.privateKey, { key: keypair.publicKey }, plaintext);
  const decrypted = skiffCrypto.stringDecryptAsymmetric(keypair.privateKey, { key: keypair.publicKey }, encrypted);

  console.log('Plaintext:', plaintext);
  console.log('Ciphertext:', encrypted);
  console.log('Expected to be true:', plaintext === decrypted);

  // Symmetric encryption example
  const symmetricKey = skiffCrypto.generateSymmetricKey();
  // A datagram is used to manage object versions and metadata
  const TestDatagram = skiffCrypto.createJSONWrapperDatagram('ddl://test');
  const symmetricPlainText = "Hello, skiff-crypto (symmetric encryption)!";
  const symmetricEncrypted = skiffCrypto.encryptSymmetric(symmetricPlainText, symmetricKey, TestDatagram);
  const symmetricDecrypted = skiffCrypto.decryptSymmetric(symmetricEncrypted, symmetricKey, TestDatagram);
  console.log('Symmetric encrypted content', symmetricEncrypted);
  console.log('Symmetric decrypted content', symmetricDecrypted);
  console.log('Expected to be true:', symmetricPlainText === symmetricDecrypted);

  // Hash example
  console.log('SHA-512 hash example', skiffCrypto.generateHash('Hello, skiff-crypto!'));