NAME
Crypt::OpenSSL::Base::Func - Base Functions, using the OpenSSL libraries
SYNOPSIS
use Crypt::OpenSSL::Base::Func;
Methods
symmetric
aes_cmac
RFC4493: aes_cmac
my $mac = aes_cmac($cipher_name, $key, $plaintext)
my $cipher_name = 'aes-128-cbc';
my $key = pack("H*", '2b7e151628aed2a6abf7158809cf4f3c');
my $msg_1 = pack("H*", '6bc1bee22e409f96e93d7e117393172a');
my $mac_1 = aes_cmac($cipher_name, $key, $msg_1);
print unpack("H*", $mac_1), "\n";
#$ echo -n '6bc1bee22e409f96e93d7e117393172a' | xxd -r -p | openssl dgst -mac cmac -macopt cipher:aes-128-cbc -macopt hexkey:2b7e151628aed2a6abf7158809cf4f3c
#(stdin)= 070a16b46b4d4144f79bdd9dd04a287c
aead_encrypt
my $r = aead_encrypt($cipher_name, $plaintext, $aad, $key, $iv, $tag_len);
# $r = [ $ciphertext, $tag ];
aead decrypt
my $plaintext = aead_decrypt($cipher_name, $ciphertext, $aad, $tag, $key, $iv);
pkcs
pkcs12_key_gen
RFC7292 : PKCS12_key_gen
see also openssl/crypto/pkcs12/p12_key.c
pkcs12_key_gen($password, $salt, $id, $iteration, $digest_name)
my $macdata_key = pkcs12_key_gen('123456', pack("H*", 'e241f01650dbeae4'), 3, 2048, 'sha256');
print unpack("H*", $macdata_key), "\n";
pkcs5_pbkdf2_hmac
RFC2898 : PBKDF2
see also openssl/crypto/evp/p5_crpt2.c
my $k = pkcs5_pbkdf2_hmac($password, $salt, $iteration, $digest_name)
my $pbkdf2_key = pkcs5_pbkdf2_hmac('123456', pack("H*", 'b698314b0d68bcbd'), 2048, 'sha256');
print unpack("H*", $pbkdf2_key), "\n";
bignum
random_bn
my $random_bn = random_bn($Nn);
my $Nn = 16;
my $random_bn = random_bn($Nn);
print $random_bn->to_hex, "\n";
hash
digest
my $dgst = digest($digest_name, $msg);
ec
gen_ec_key
my $priv_pkey = gen_ec_key(group_name, $priv_hex);
gen_ec_pubkey
my $pub_pkey = gen_ec_pubkey(group_name, $pub_hex);
export_ec_pubkey
my $pub_pkey = export_ec_pubkey($priv_pkey);
read_ec_pubkey
my $pub_hex = read_ec_pubkey($pub_pkey, $want_compressed);
ecdh
my $z_bin = ecdh($local_priv_pkey, $peer_pub_pkey);
ecdh_pem
my $z_bin = ecdh_pem($local_priv_pem_file, $peer_pub_pem_file);
pkey
read_key
my $priv_hex = read_key($priv_pkey);
read_pubkey
my $pub_hex = read_pubkey($pub_pkey);
read_key_from_pem
my $priv_pkey = read_key_from_pem($priv_pem_filename);
read_pubkey_from_pem
my $pub_pkey = read_pubkey_from_pem($pub_pem_filename);
read_key_from_der
my $priv_pkey = read_key_from_der($priv_der_filename);
read_pubkey_from_der
my $pub_pkey = read_pubkey_from_der($pub_der_filename);
write_key_to_pem
write_key_to_pem($dst_fname, $priv_pkey);
write_pubkey_to_pem
write_key_to_pem($dst_fname, $pub_pkey);
write_key_to_der
write_key_to_der($dst_fname, $priv_pkey);
write_pubkey_to_der
write_key_to_der($dst_fname, $pub_pkey);
get_pkey_bn_param
my $x_bn = get_pkey_bn_param($pkey, $param_name);
get_pkey_octet_string_param
my $x_hex = get_pkey_octet_string_param($pkey, $param_name);
get_pkey_utf8_string_param
my $s = get_pkey_utf8_string_param($pkey, $param_name);