Crypto Provider
Class Name |
CryptoProvider |
|---|---|
Extends |
|
Source |
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
cryptors-any: object with availableCryptors.
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
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
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
options-any: options which will passed to the cryptor to work (like key for encryption)generateKey-function: generates a random key for encryption/decryptiongetCryptoInfo-function: returns a empty CryptoInfo object for the current Cryptorencrypt-function: function to encrypt a given messagedecrypt-function: function to decrypt a given message
Envelope
algorithm-string: algorithm used for encryptionblock-number(optional): block number for which related item is encryptedcryptorVersion-number(optional): version of the cryptor used. describes the implementation applied during decryption and not the algorithm version.originator-string(optional): context for encryption, this can bea 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
keyLength-number(optional): length of the key used in encryption
CryptoInfo
public-any(optional): unencrypted part of the data; will stay as is during encryptionprivate-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 valuecryptoInfo-CryptoInfo: describes used encryption