Class DataEncryptor

This class is used to encrypt an decrypt data with a password

Source : file core/lib/DataEncryptor.js at line 29

Constructor

new DataEncryptor ( salt )

The constructor

Source : file core/lib/DataEncryptor.js at line 125

Parameters

Name Type Description
salt String

Salt to be used for encoding and decoding operations. If none, a default value is provided.

Public methods

decryptData ( data, onOk, onError, pswdPromise )

This method decrypt data with a password

Source : file core/lib/DataEncryptor.js at line 167

Parameters

Name Type Description
data Uint8Array

The data to decrypt. See TextDecoder ( ) to transform Uint8Array to string

onOk Function

A function to execute when the decryption succeeds

onError Function

A function to execute when the decryption fails

pswdPromise Promise

A Promise that fullfil with a password. Typically a dialog...

encryptData ( data, onOk, onError, pswdPromise )

This method encrypt data with a password

Source : file core/lib/DataEncryptor.js at line 140

Parameters

Name Type Description
data Uint8Array

The data to encrypt. See TextEncoder ( ) to transform string to Uint8Array

onOk Function

A function to execute when the encryption succeeds

onError Function

A function to execute when the encryption fails

pswdPromise Promise

A Promise that fullfil with a password. Typically a dialog...

Private properties

#salt : String

Salt to be used for encoding and decoding operations.

Source : file core/lib/DataEncryptor.js at line 36

Private methods

#decrypt ( decryptKey, data )

Call the decrypt() method of the SubtleCrypto interface

Source : file core/lib/DataEncryptor.js at line 90

Parameters

Name Type Description
decryptKey CryptoKey

The key to use for decryption

data Uint8Array

The data to decode

Returns

A Promise which will be fulfilled with the decrypted data as a Uint8Array. Use TextDecoder.decode ( ) to transform to string
Type : Promise

#deriveKey ( masterKey, salt )

Call the deriveKey() method of the SubtleCrypto interface

Source : file core/lib/DataEncryptor.js at line 64

Parameters

Name Type Description
masterKey CryptoKey

The CryptoKey returned by the onOk handler of the Promise returned by #importKey

salt String

The salt to use

Returns

A Promise which will be fulfilled with a CryptoKey object representing the secret key derived from the master key
Type : Promise

#encrypt ( encryptKey, ivBytes, data )

Call the encrypt() method of the SubtleCrypto interface

Source : file core/lib/DataEncryptor.js at line 109

Parameters

Name Type Description
encryptKey CryptoKey

The key to use for encryption

ivBytes Uint8Array

A Uint8Array with random values used for encoding

data Uint8Array

The data to encode transformed to a Uint8Array with TextEncoder.encode ( )

Returns

A Promise which will be fulfilled with the encrypted data as a Uint8Array
Type : Promise

#importKey ( pswd )

Call the importKey() method of the SubtleCrypto interface

Source : file core/lib/DataEncryptor.js at line 46

Parameters

Name Type Description
pswd Uint8Array

The password to use, encode with TextEncoder.encode ( )

Returns

A Promise that fulfills with the imported key as a CryptoKey object
Type : Promise