NAME
Dipki::Cipher - Generic Block Cipher functions.
BlockBytes function
Return the block size in bytes for a given cipher algorithm.
Example
use Dipki;
say Dipki::Cipher::BlockBytes(Dipki::Cipher::AES256);
# 16
KeyBytes function
Return the key size in bytes for a given cipher algorithm.
Example
use Dipki;
say Dipki::Cipher::KeyBytes(Dipki::Cipher::AES256);
# 32
Encrypt function
Encrypt data in a byte array using the specified block cipher algorithm, mode and padding.
Synopsis
$ct = Dipki::Cipher::Encrypt($data, $key, $iv, $algmodepad[, $opts]);
Parameters
- $data
-
Data to be encrypted.
- $prikeyfile
-
Key of exact length for block cipher algorithm (see Cipher::KeyBytes).
- $iv
-
Initialization Vector (IV) of exactly the block size (see Cipher::BlockBytes) or
""
for ECB mode. - $algmodepad
-
String containing the block cipher algorithm, mode and padding, e.g. C<"Aes128/CBC/OneAndZeroes">. Alternatively, set $algmodepad as C<""> and use option flags for Alg, Mode and Padding in the $opts parameter.
- $opts
-
Options. Add Cipher::PREFIXIV to prepend the IV to the output.
Example
use Dipki;
$ct = Dipki::Cipher::Encrypt($pt, $key, $iv, "Aes128/CBC/OneAndZeroes", Dipki::Cipher::PREFIXIV);
$ct = Dipki::Cipher::Encrypt($pt, $key, $iv, "", Dipki::Cipher::AES128 | Dipki::Cipher::CBC | Dipki::Cipher::ONEANDZEROES | Dipki::Cipher::PREFIXIV);
Decrypt function
Decrypt data in a byte array using the specified block cipher algorithm, mode and padding.
Synopsis
$pt = Dipki::Cipher::Decrypt($data, $key, $iv, $algmodepad[, $opts]);
EncryptBlock function
Encrypt a block of data using a block cipher.
Synopsis
$ct = Dipki::Cipher::EncryptBlock($data, $key, $iv, $alg, $mode);
Notes
Input data must be an exact multiple of block length for ECB and CBC mode. Output is always the same length as the input.
DecryptBlock function
Decrypt a block of data using a block cipher.
Synopsis
$pt = Dipki::Cipher::DecryptBlock($data, $key, $iv, $alg, $mode);
Notes
Input data must be an exact multiple of block length for ECB and CBC mode. Output is always the same length as the input.
KeyWrap function
Wrap (encrypt) key material with a key-encryption key.
Synopsis
$wk = Dipki::Cipher::KeyWrap($data, $kek, $alg);
KeyUnwrap function
Unwrap (decrypt) key material with a key-encryption key.
Synopsis
$k = Dipki::Cipher::KeyUnwrap($data, $kek, $alg);
EncryptAEAD function
Encrypt data using the AES-GCM authenticated encryption algorithm.
Synopsis
$wk = Dipki::Cipher::EncryptAEAD($data, $key, $iv, $aeadalg[, $opts, $aad]);
NOTE
Note order of arguments with optional parameter $add last after $opts.
DecryptAEAD function
Decrypt data using the AES-GCM authenticated encryption algorithm.
Synopsis
$wk = Dipki::Cipher::DecryptAEAD($data, $key, $iv, $aeadalg[, $opts, $aad]);
AUTHOR
David Ireland, https://www.cryptosys.net/contact/
COPYRIGHT AND LICENSE
Copyright (C) 2022 David Ireland, DI Management Services Pty Limited, https://www.di-mgt.com.au https://www.cryptosys.net. The code in this module is licensed under the terms of the MIT license. For a copy, see http://opensource.org/licenses/MIT