Crypto Provider

Class Name CryptoProvider
Extends CryptoProvider
Source crypto-provider.ts

The CryptoProvider is a container for supported Cryptors and is able to determine, which Cryptor to use for encryption / decryption.


constructor

new CryptoProvider(cryptors);

Creates a new CryptoProvider instance.

Parameters

  1. cryptors - any: object with available Cryptors.

Returns

CryptoProvider instance

Example

const serviceContract = new CryptoProvider({
    cryptors: {
      aes: new Aes(),
      unencrypted: new Unencrypted()
    }
  });

getCryptorByCryptoAlgo

cryptoProvider.getCryptorByCryptoAlgo(cryptoAlgo);

get a Cryptor matching the crypto algorithm

Parameters

  1. cryptoAlgo - string: crypto algorithm

Returns

Cryptor: matching cryptor.

Example

const cryptor = runtime.cryptoProvider.getCryptorByCryptoAlgo('aes');

getCryptorByCryptoInfo

cryptoProvider.getCryptorByCryptoInfo(info);

get a Cryptor matching the provided CryptoInfo

Parameters

  1. info - CryptoInfo: details about en-/decryption

Returns

Cryptor: matching cryptor.

Example

const cryptoInfo = {
  "public": {
    "name": "envelope example"
  },
  "private": "...",
  "cryptoInfo": {
    "algorithm": "unencrypted",
    "keyLength": 256,
    "originator": "0x0000000000000000000000000000000000000001,0x0000000000000000000000000000000000000002",
    "block": 123
  }
};
const cryptor = runtime.cryptoProvider.getCryptorByCryptoInfo(cryptoInfo);

= Additional Components =

Interfaces

Cryptor

  1. options - any: options which will passed to the cryptor to work (like key for encryption)
  2. generateKey - function: generates a random key for encryption/decryption
  3. getCryptoInfo - function: returns a empty CryptoInfo object for the current Cryptor
  4. encrypt - function: function to encrypt a given message
  5. decrypt - function: function to decrypt a given message

Envelope

  1. algorithm - string: algorithm used for encryption

  2. block - number (optional): block number for which related item is encrypted

  3. cryptorVersion - number (optional): version of the cryptor used. describes the implementation applied during decryption and not the algorithm version.

  4. originator - string (optional): context for encryption, this can be

    • a context known to all parties (e.g. key exchange)
    • a key exchanged between two accounts (e.g. bmails)
    • a key from a sharings info from a contract (e.g. DataContract)

    defaults to 0

  5. keyLength - number (optional): length of the key used in encryption

CryptoInfo

  1. public - any (optional): unencrypted part of the data; will stay as is during encryption
  2. private - any (optional): encrypted part of the data. If encrypting, this part will be encrypted, depending on the encryption. If already encrypted, this will be the encrypted value
  3. cryptoInfo - CryptoInfo: describes used encryption