NeptuneCrypto

NeptuneCrypto

Members

(static) Errors

Errors thrown by NeptuneCrypto
Source:

Methods

(static) decrypt(encryptedText, key) → {string}

Decrypts data using the encrypted data and key.\ Encrypted data needs to be in a special format, `ncrypt::version:a:b:c:d:e:f` with `:g:i` added at the end for AEAD ciphers
Source:
Parameters:
Name Type Description
encryptedText string | Buffer Encrypted data provided by the encrypt function (at some point).
key string Key used to encrypt the data. HKDF used to derive actual encryption key.
Throws:
  • Parameter types are incorrect.
    Type
    TypeError
  • Unable to find the encryption prefix, likely data is not even encrypted.
    Type
    DataNotEncrypted
  • Data not stored correctly, cannot split on ':' enough times to be valid.
    Type
    EncryptedDataSplitError
  • Not sure how to decrypt this data, how is it stored (which parts mean what)?
    Type
    EncryptedDataInvalidVersion
  • Unsupported cipher used to encrypt the data
    Type
    UnsupportedCipher
  • Wrong decryption key used
    Type
    InvalidDecryptionKey
  • Missing the decryption key
    Type
    MissingDecryptionKey
Returns:
Type:
string
Decrypted text

(static) encrypt(plainText, key, saltopt, optionsopt) → {string}

Encrypts plain text data using the requested algorithm and key. Uses HKDF to derive the actual encryption keys from your provided key.
Source:
Parameters:
Name Type Attributes Description
plainText string Plain text you wish to encrypt
key string Encryption key (we'll use HKDF to derive the actual key)
salt string <optional>
Encryption salt (passed to HKDF). If undefined, a random string of length 32 will be used
options EncryptionOptions <optional>
Misc options, such as the hash algorithm or cipher used.
Throws:
  • Parameter types are incorrect
    Type
    TypeError
  • Unsupported cipher requested
    Type
    UnsupportedCipher
Returns:
Type:
string
Encrypted data

(static) HKDF(sharedSerect, saltopt, optionsopt) → {AESKey}

Derive an encryption key from a shared secret
Source:
Parameters:
Name Type Attributes Description
sharedSerect string | int The shared secret
salt string <optional>
The shared or stored salt
options HKDFOptions <optional>
Additional things you can tweak (key length, iv length, hash algorithm)
Returns:
Type:
AESKey
AES key and IV

(static) randomString(len, minCharopt, maxCharopt)

Generates a random string. Does not touch the RNG seed, recommend you set that first.
Source:
Parameters:
Name Type Attributes Default Description
len int Length of random string
minChar int <optional>
33 The lower character code. Must be >=33 (no control characters).
maxChar int <optional>
128 The upper character code. Must be <=220, but weird stuff happens above 128 (standard ASCII)