OpenSSL Encryption Library


Encryption Resources

Name -- Syntax / Description
crypto_base64_decode
crypto_base64_decode( data )
Decodes and returns Base-64 decodes data.
Returns the decrypted data
  • data = the information to decode
crypto_base64_encode
crypto_base64_encode( data )
Encodes and returns Base-64 encoded data.
Returns the encrypted data
  • data = the information to encode
crypto_hmac_sha1
crypto_hmac_sha1( value, key, output_format, output)
Calculates an HMAC SHA-1 (Hash-based Message Authentication Code) of value
returns: 1 on success, 0 on failure (including OpenSSL not being available)
  • value = value to hash by reference
  • key = key to use to calculate the hmac
  • output_format = 'hex' or 'binary'
  • output = hmac_sha1 hash value.
crypto_hmac_sha256
crypto_hmac_sha256( buffer var, key, format, result var )
Calculates an HMAC SHA-256 (Hash-based Message Authentication Code) of buffer
Returns 1 on success, 0 on error or if on an unsuported platform.
  • buffer = value to hash
  • key = binary key to use to calculate the hmac
  • format = "binary" or "hex"
  • result = a variable used to store the results.
crypto_last_error
crypto_last_error()
Returns the error text from the last SSL error, or other internal errors in the crypto suite of functions. Use crypto_last_ssl_error() instead to get the code of the last SSL error.
Returns error text.
crypto_last_ssl_error
crypto_last_ssl_error()
Returns the Integer value of the last SSL error code. Use crypto_last_error() instead to get the text of the last SSL error.
Returns error code.
crypto_library_version
crypto_library_version( info )
crypto_md5
crypto_md5( buffer )
Calculates the MD5 hash of a string.
Returns the MD5 hash value.
  • buffer = the data to be hashed.
crypto_md5_file
crypto_md5_file( file, location, hash var )
Calculates the md5 hash of a file
Returns 1 on success, 0 on failure.
  • file = Name of file to calculate the hash of
  • location = Location either "script" or "data"
  • hash = MD5 hash value
crypto_rand_bytes
crypto_rand_bytes( n )
Generates n random bytes.
Returns a string of bytes
  • n = the number of bytes
crypto_sha1
crypto_sha1( buffer var, format, result var )
Returns an SHA1 hash of buffer. Secure Hash Algorithm
Returns 1 on success, 0 on failure. (including OpenSSL not being available)
  • buffer = value to hash by reference
  • output_format = 'hex' or 'binary'. Anything else will result in binary output.
  • output = returned sha1 hash value.
crypto_sha256
crypto_sha256( buffer var, format, result var )
Returns an SHA256 hash of buffer. Secure Hash Algorithm. May not be available on platforms running versions of OpenSSL Older than v0.9.8.
Returns 1 on success, 0 on failure. (including OpenSSL not being available)
  • buffer = value to hash by reference
  • output_format = 'hex' or 'binary'. Anything else will result in binary output.
  • output = returned sha1 hash value.
crypto_cipher_block_size
crypto_cipher_block_size( ciphername )
Programatically determine the block size attribute of the cipher specified by "ciphername".
returns the numeric size, in bytes, or -1 if an invalid "ciphername" is specified.
  • ciphername = an OpenSSL cipher identifier, such as "aes-128-cbc" or "rc2-ofb".
crypto_cipher_key_length
crypto_cipher_key_length( ciphername )
Programatically determine the key_length attribute of the cipher specified by "ciphername".
returns the numeric size, in bytes, or -1 if an invalid "ciphername" is specified.
  • ciphername = an OpenSSL cipher identifier, such as "aes-128-cbc" or "rc2-ofb".
crypto_cipher_iv_length
crypto_cipher_iv_length( ciphername )
Programatically determine the iv_length attribute of the cipher specified by "ciphername".
returns the numeric size, in bytes, or -1 if an invalid "ciphername" is specified.
  • ciphername = an OpenSSL cipher identifier, such as "aes-128-cbc" or "rc2-ofb".
crypto_cipher_mode
crypto_cipher_mode( ciphername )
Returns the block mode of operation of the cipher specified by "ciphername."
  • where ciphername = an OpenSSL cipher identifier, such as "aes-128-cbc" or "rc2-ofb"
crypto_evp_encrypt
crypto_evp_encrypt( ciphername, key, iv, plaintext, encrypted var )
Encrypts "plaintext" using the block cipher specified by "ciphername", placing the encrypted data into "encrypted".
returns 1 on success, 0 on failure
  • ciphername = The OpenSSL identifier of the cipher, such as "bf-cbc" or "des-ede3-cbc".
  • key = The encryption key. Must be exactly the number of bytes required by the cipher, as returned by crypto_cipher_key_length.
  • iv = An initialization vector, if required by the cipher. Must be exactly the number of bytes required by the cipher, as returned by crypto_cipher_iv_length.
  • plaintext = The text to be encrypted
  • encrypted = [output] Receives the cipher text
crypto_evp_decrypt
crypto_evp_decrypt( ciphername, key, iv, encrypted, plaintext var )
Decrypts "plaintext" using the block cipher specified by "ciphername", placing the decrypted data into "plaintext".
Return 1 on success, 0 on failure.
  • ciphername = The OpenSSL identifier of the cipher, such as "bf-cbc" or "des-ede3-cbc".
  • key = The key used for encryption.
  • iv = The initialization vector used for encryption. returned by crypto_cipher_iv_length().
  • encrypted = The ciphertext to be decrypted
  • plaintext = [output] Receives the plaintext
crypto_digest_block_size
crypto_digest_block_size( digestname )
Programatically determines the block_size attribute of the digest algorithm specified by "digestname".
Returns the numeric size, in bytes, or -1 if an invalid "digestname" is specified.
  • digestname = an OpenSSL digest identifier, such as "sha256" or "md5".
crypto_digest_size
crypto_digest_size( digestname )
Programatically determines the digest_size attribute of the digest algorithm specified by "digestname".
Returns the numeric size, in bytes, or -1 if an invalid "digestname" is specified.
  • digestname = an OpenSSL digest identifier, such as "sha256" or "md5".
crypto_evp_digest
crypto_evp_digest( digestname, buffer var, digest var )
Calculates the digest of "buffer" using digest algorithm "digestname", placing the calculated digest in "digest". The digest output is always in raw binary format, use miva_hex_encode() or crypto_base64_encode() if other output formats are desired.
Returns 1 on success or 0 if an invalid or unsupported "digestname" is specified.
  • digestname = an OpenSSL digest identifier, such as "sha256" or "md5". buffer =
  • digest =
crypto_evp_hmac
crypto_evp_hmac( digestname, key, buffer var, digest var )
Calculates the HMAC of "buffer" using digest algorithm "digestname" and key "key", placing the HMAC in "digest". The HMAC output is always in raw binary format, use miva_hex_encode() or crypto_base64_encode() if other output formats are desired.
Returns 1 on success or 0 if an invalid or unsupported "digestname" is specified.
  • digestname = an OpenSSL digest identifier, such as "sha256" or "md5".
  • buffer = The data that will be process.
  • digest = The result of the HMAC function.
crypto_xor
crypto_xor( buffer var, dest var )
Efficiently performs a byte-by-byte XOR of buffer and dest, storing the resulting data in "dest". If "buffer" is longer than "dest", any extra bytes are ignored.
Returns nothing.
  • buffer = the data that will be processed.
  • dest = the data that will processed against buffer and will contain the results.
crypto_pbkdf1
crypto_pbkdf1( digestname, password, salt, iterations, dklen, dk var )
Derives a key of "dklen" bytes using PBKDF1 from PKCS #5.
Returns 1 on success or 0 on error.
  • digestname = The digest algorithm to use. Must be one of "md2", "md5" or "sha1". password = The password from which a key is to be derived.
  • salt = Exactly 8 bytes of random data that are used as a salt.
  • iterations = The number of iterations to perform.
  • dklen = The desired output length of the derived key. May not be longer than the output digest size of the specified digest algorithm.
  • dk = [output] Receives the derived key. The output is in raw binary.
crypto_pbkdf2
crypto_pbkdf2( digestname, password, salt, iterations, dklen, dk var )
Derives a key of "dklen" bytes using PBKDF2 from PKCS #5.
Returns 1 on success or 0 on error.
  • digestname = The digest algorithm to use. May be any of the digests supported by the installed OpenSSL version.
  • password = The password from which a key is to be derived.
  • salt = Random data of any length that is used to salt the derivation. RFC 2898 recommends a minimum salt length of 8 bytes.
  • iterations = The number of iterations to perform. RFC 2898 recommends at least 1000 iterations.
  • dklen = The desired output length of the derived key. May be any positive value.
  • dk = [output] Receives the derived key. The output is in raw binary.
crypto_hmac_md5
crypto_hmac_md5( buffer var, key, format, result var )
Performs an HMAC-MD5 on "buffer" using key "key", storing the result in "result".
Returns 1 on success, 0 on error.
  • buffer = the data that will be processed.
  • key = the encryption key
  • format = on of the literal string "hex" or "binary"
  • result = the return data.
User Annotations: crypto