Decipher

D.crypto. Namespace

Decipher

Description:
  • Returned by D.crypto.createDecipher.

    Instances of the Decipher object are used to decrypt data.
    The object can be used in one of two ways:

    • As a stream that is both readable and writable, where plain encrypted data is written to produce unencrypted data on the readable side
    • Using the decipher.update() and decipher.final() methods to produce the unencrypted data.

Methods

(static) final(outputEncodingopt) → {string|Buffer}

Description:
  • Returns any remaining plaintext which is deciphered.
    If outputEncoding is specified, a string is returned. If an outputEncoding is not provided, a Buffer is returned.

    Once the decipher.final() method has been called, the Decipher object can no longer be used to decrypt data.
    Attempts to call decipher.final() more than once will result in an error being thrown.

Example
D.crypto.createDecipher('sha1', 'key', 'initialization vector').final('binary')
Parameters:
Name Type Attributes Description
outputEncoding binary | base64 | hex <optional>
The outputEncoding specifies the output format of the enciphered data, and can be 'binary', 'base64' or 'hex'.
If no encoding is provided, then a buffer is returned.
Returns:
- Any remaining deciphered data
Type
string | Buffer

(static) setAutoPadding(autoPaddingopt)

Description:
  • When data has been encrypted without standard block padding, calling decipher.setAutoPadding(false) will disable automatic padding to prevent decipher.final() from checking for and removing padding.
    Turning auto padding off will only work if the input data's length is a multiple of the cipher's block size.

    The decipher.setAutoPadding() method must be called before decipher.final().

Example
D.crypto.createDecipher('sha1', 'key', 'initialization vector').setAutoPadding(false)
Parameters:
Name Type Attributes Default Description
autoPadding bool <optional>
true The auto padding boolean flag.

(static) update(data, inputEncodingopt, outputEncodingopt) → {string|Buffer}

Description:
  • Updates the decipher with data.
    The decipher.update() method can be called multiple times with new data until decipher.final() is called.
    Calling decipher.update() after decipher.final() will result in an error being thrown.

    Input Encoding options:

    • If the inputEncoding argument is given, the data argument is a string using the specified encoding.
    • If the inputEncoding argument is not given, data must be a Buffer.
    • If data is a Buffer then inputEncoding is ignored.
    Output Encoding options:
    • If the outputEncoding is specified, a string using the specified encoding is returned.
    • If no outputEncoding is provided, a Buffer is returned.
Example
D.crypto.createDecipher('sha1', 'key', 'initialization vector').update('data', 'binary', 'binary')
Parameters:
Name Type Attributes Description
data string | Buffer The data object.
inputEncoding binary | ascii | utf8 <optional>
The encoding of the data string.
If data is a Buffer this argument is ignored.
outputEncoding binary | base64 | hex <optional>
The encoding of the return value.
The output encoding specifies the output format of the enciphered data, and can be 'binary', 'base64' or 'hex'.
If no encoding is provided, then a buffer is returned.
Returns:
- Returns the deciphered data
Type
string | Buffer