Simple Crypto
The Simple Crypto Interface provides a simple way to manage cryptographic operations such as encryption, decryption, signing and verifying signature. Key generation and storage is managed automatically and leverage high standard cryptographic primitives (AES-GCM for encryption, ECDSA with NIST P-256 curve for signature and verification, SHA2 and SHA3 for digest).
Using Simple Crypto APIs from Applications
Data Encryption and Decryption
Class | Operation | Parameters: type | Returns | Behavior |
---|---|---|---|---|
Crypto.AES | generateKey | keyName: string | Result<KeyAES, Error> | Generate an AES-256 key and store it in the ledger with the keyName provided. Return a ResultSet Result<KeyAES, Error> containing either the generated KeyAES or an Error . |
Crypto.AES | getKey | keyName: string | KeyAES | null | Get the key associated with the specified keyName , return null if key does not exists. |
KeyAES | encrypt | data: ArrayBuffer | Result<ArrayBuffer, Error> | Encrypt the data using AES-GCM. the IV is managed automatically. Return a ResultSet Result<ArrayBuffer, Error> containing the encrypted data as an ArrayBuffer or an Error . |
KeyAES | decrypt | data: ArrayBuffer | Result<ArrayBuffer, Error> | Decrypt the data using AES-GCM. the IV is managed automatically. Return a ResultSet Result<ArrayBuffer, Error> containing the decrypted data as an ArrayBuffer or an Error . |
the generateKey
method can be used only in the context of a transaction
as the generated keys are saved into the ledger
.
The interface can be accessed through the Crypto.AES
keyword.
ECDSA: Signing and verifying
Class | Operation | Parameters: type | Returns | Behavior |
---|---|---|---|---|
Crypto.ECDSA | generateKey | keyName: string | Result<KeyECC, Error> | Generate a NIST P-256 key and store it in the ledger with the keyName provided. Return a ResultSet Result<KeyECC, Error> containing either the generated KeyECC or an Error . |
Crypto.ECDSA | getKey | keyName: string | KeyECC | null | Get the key associated with the specified keyName , return null if key does not exists. |
KeyECC | sign | data: ArrayBuffer | Result<ArrayBuffer, Error> | Provide an ECDSA signature of data . Return a ResultSet Result<ArrayBuffer, Error> containing the signature as an ArrayBuffer or an Error . |
KeyECC | verify | data: ArrayBuffer, signature: ArrayBuffer | Result<VerifySignResult, Error> | Verify the signature from the data provided. Return a ResultSet Result<VerifySignResult, Error> containing the signature verification VerifySignResult or an Error . |
the generateKey
method can be used only in the context of a transaction
as the generated keys are saved into the ledger
.
The interface can be accessed through the Crypto.ECDSA
keyword.
Making data digest
The interface can be accessed through the Crypto.SHA
keyword and is compatible with SHA2 and SHA3 digest.
Class | Operation | Parameters: type | Returns | Behavior |
---|---|---|---|---|
Crypto.SHA | digest | algorithm: string, data: ArrayBuffer | Result<ArrayBuffer, Error> | Generate a digest of the data based on the algorithm specified. Return a ResultSet Result<ArrayBuffer, Error> containing either the digest in an ArrayBuffer or an Error . |