Module cipher

cipher module do encrypt or decrypt base on OpenSSL EVP API.

Usage:

    cipher = require('openssl').cipher
    

Functions

list ([alias]) list all support cipher algs
get (alg) get evp_cipher object
encrypt (alg, input, key[, iv[, pad[, engine]]]) quick encrypt
decrypt (alg, input, key[, iv[, pad[, engine]]]) quick decrypt
cipher (alg, encrypt, input, key[, iv[, pad[, engine]]]) quick encrypt or decrypt
new (alg, encrypt[, key[, iv[, pad[, engine]]]]) get evp_cipher_ctx object for encrypt or decrypt
encrypt_new (alg, key[, iv[, engine]]) get evp_cipher_ctx object for encrypt
decrypt_new (alg, key[, iv[, engine]]) get evp_cipher_ctx object for decrypt

Class evp_cipher

evp_cipher:info () get infomation of evp_cipher object
evp_cipher:BytesToKey (data, string, md) derive key
evp_cipher:new (encrypt, key[, iv[, pad[, engine]]]) get evp_cipher_ctx to encrypt or decrypt
evp_cipher:encrypt_new (key[, iv[, pad[, engine]]]) get evp_cipher_ctx to encrypt
evp_cipher:decrypt_new (key[, iv[, pad[, engine]]]) get evp_cipher_ctx to decrypt
evp_cipher:cipher (encrypt, input, key[, iv[, pad[, engine]]]) do encrypt or decrypt
evp_cipher:encrypt (input, key[, iv[, pad[, engine]]]) do encrypt
evp_cipher:decrypt (input, key[, iv[, pad[, engine]]]) do decrypt

Class evp_cipher_ctx

evp_cipher_ctx:init (key[, iv]) init encrypt/decrypt cipher ctx
evp_cipher_ctx:update (msg) feed data to do cipher
evp_cipher_ctx:final () get result of cipher
evp_cipher_ctx:info () get infomation of evp_cipher_ctx object


Functions

list ([alias])
list all support cipher algs

Parameters:

  • alias boolean include alias names for cipher alg, default true (optional)

Returns:

    all cipher methods
get (alg)
get evp_cipher object

Parameters:

  • alg string, integer or asn1_object name, nid or object identity

Returns:

    evp_cipher cipher object mapping EVP_MD in openssl

See also:

encrypt (alg, input, key[, iv[, pad[, engine]]])
quick encrypt

Parameters:

  • alg string, integer or asn1_object name, nid or object identity
  • input string data to encrypt
  • key string secret key
  • iv string (optional)
  • pad boolean true for padding default (optional)
  • engine engine custom crypto engine (optional)

Returns:

    string result encrypt data
decrypt (alg, input, key[, iv[, pad[, engine]]])
quick decrypt

Parameters:

  • alg string, integer or asn1_object name, nid or object identity
  • input string data to decrypt
  • key string secret key
  • iv string (optional)
  • pad boolean true for padding default (optional)
  • engine engine custom crypto engine (optional)

Returns:

    string result decrypt data
cipher (alg, encrypt, input, key[, iv[, pad[, engine]]])
quick encrypt or decrypt

Parameters:

  • alg string, integer or asn1_object name, nid or object identity
  • encrypt boolean true for encrypt,false for decrypt
  • input string data to encrypt or decrypt
  • key string secret key
  • iv string (optional)
  • pad boolean true for padding default (optional)
  • engine engine custom crypto engine (optional)

Returns:

    string result
new (alg, encrypt[, key[, iv[, pad[, engine]]]])
get evp_cipher_ctx object for encrypt or decrypt

Parameters:

  • alg string, integer or asn1_object name, nid or object identity
  • encrypt boolean true for encrypt,false for decrypt
  • key string secret key (optional)
  • iv string (optional)
  • pad boolean true for padding default (optional)
  • engine engine custom crypto engine (optional)

Returns:

    evp_cipher_ctx cipher object mapping EVP_CIPHER_CTX in openssl

See also:

encrypt_new (alg, key[, iv[, engine]])
get evp_cipher_ctx object for encrypt

Parameters:

  • alg string, integer or asn1_object name, nid or object identity
  • key string secret key
  • iv string (optional)
  • engine engine custom crypto engine (optional)

Returns:

    evp_cipher_ctx cipher object mapping EVP_CIPHER_CTX in openssl

See also:

decrypt_new (alg, key[, iv[, engine]])
get evp_cipher_ctx object for decrypt

Parameters:

  • alg string, integer or asn1_object name, nid or object identity
  • key string secret key
  • iv string (optional)
  • engine engine custom crypto engine (optional)

Returns:

    evp_cipher_ctx cipher object mapping EVP_CIPHER_CTX in openssl

See also:

Class evp_cipher

openssl.evp_cipher object
evp_cipher:info ()
get infomation of evp_cipher object

Returns:

    table info keys include name,block_size,key_length,iv_length,flags,mode
evp_cipher:BytesToKey (data, string, md)
derive key

Parameters:

  • data string derive data
  • string string[opt] salt salt will get strong security
  • md ev_digest or string digest method used to diver key, default with ‘sha1’

Returns:

  1. string key
  2. string iv
evp_cipher:new (encrypt, key[, iv[, pad[, engine]]])
get evp_cipher_ctx to encrypt or decrypt

Parameters:

  • encrypt boolean true for encrypt,false for decrypt
  • key string secret key
  • iv string (optional)
  • pad boolean true for padding default (optional)
  • engine engine custom crypto engine (optional)

Returns:

    evp_cipher_ctx evp_cipher_ctx object

See also:

evp_cipher:encrypt_new (key[, iv[, pad[, engine]]])
get evp_cipher_ctx to encrypt

Parameters:

  • key string secret key
  • iv string (optional)
  • pad boolean true for padding default (optional)
  • engine engine custom crypto engine (optional)

Returns:

    evp_cipher_ctx evp_cipher_ctx object

See also:

evp_cipher:decrypt_new (key[, iv[, pad[, engine]]])
get evp_cipher_ctx to decrypt

Parameters:

  • key string secret key
  • iv string (optional)
  • pad boolean true for padding default (optional)
  • engine engine custom crypto engine (optional)

Returns:

    evp_cipher_ctx evp_cipher_ctx object

See also:

evp_cipher:cipher (encrypt, input, key[, iv[, pad[, engine]]])
do encrypt or decrypt

Parameters:

  • encrypt boolean true for encrypt,false for decrypt
  • input string data to encrypt or decrypt
  • key string secret key
  • iv string (optional)
  • pad boolean true for padding default (optional)
  • engine engine custom crypto engine (optional)

Returns:

    string result
evp_cipher:encrypt (input, key[, iv[, pad[, engine]]])
do encrypt

Parameters:

  • input string data to encrypt
  • key string secret key
  • iv string (optional)
  • pad boolean true for padding default (optional)
  • engine engine custom crypto engine (optional)

Returns:

    string result
evp_cipher:decrypt (input, key[, iv[, pad[, engine]]])
do decrypt

Parameters:

  • input string data to decrypt
  • key string secret key
  • iv string (optional)
  • pad boolean true for padding default (optional)
  • engine engine custom crypto engine (optional)

Returns:

    string result

Class evp_cipher_ctx

openssl.evp_cipher_ctx object
evp_cipher_ctx:init (key[, iv])
init encrypt/decrypt cipher ctx

Parameters:

Returns:

    boolean result and followd by error reason
evp_cipher_ctx:update (msg)
feed data to do cipher

Parameters:

Returns:

    string result parture result
evp_cipher_ctx:final ()
get result of cipher

Returns:

    string result last result
evp_cipher_ctx:info ()
get infomation of evp_cipher_ctx object

Returns:

    table info keys include block_size,key_length,iv_length,flags,mode,nid,type, evp_cipher
generated by LDoc 1.5.0 Last updated 2024-05-16 23:31:39