NAME
Crypt::PK::RSA - Public key cryptography based on RSA
SYNOPSIS
### OO interface
#Encryption: Alice
my $pub = Crypt::PK::RSA->new('Bob_pub_rsa1.der');
my $ct = $pub->encrypt("secret message");
#
#Encryption: Bob (received ciphertext $ct)
my $priv = Crypt::PK::RSA->new('Bob_priv_rsa1.der');
my $pt = $priv->decrypt($ct);
#Signature: Alice
my $priv = Crypt::PK::RSA->new('Alice_priv_rsa1.der');
my $sig = $priv->sign($message);
#
#Signature: Bob (received $message + $sig)
my $pub = Crypt::PK::RSA->new('Alice_pub_rsa1.der');
$pub->verify($sig, $message) or die "ERROR";
#Shared secret
my $priv = Crypt::PK::RSA->new('Alice_priv_rsa1.der');
my $pub = Crypt::PK::RSA->new('Bob_pub_rsa1.der');
my $shared_secret = $priv->shared_secret($pub);
#Key generation
my $pk = Crypt::PK::RSA->new();
$pk->generate_key(256, 65537);
my $private_der = $pk->export_key_der('private');
my $public_der = $pk->export_key_der('public');
my $private_pem = $pk->export_key_pem('private');
my $public_pem = $pk->export_key_pem('public');
### Functional interface
#Encryption: Alice
my $ct = rsa_encrypt('Bob_pub_rsa1.der', "secret message");
#Encryption: Bob (received ciphertext $ct)
my $pt = rsa_decrypt('Bob_priv_rsa1.der', $ct);
#Signature: Alice
my $sig = rsa_sign('Alice_priv_rsa1.der', $message);
#Signature: Bob (received $message + $sig)
rsa_verify('Alice_pub_rsa1.der', $sig, $message) or die "ERROR";
#Shared secret
my $shared_secret = rsa_shared_secret('Alice_priv_rsa1.der', 'Bob_pub_rsa1.der');
FUNCTIONS
rsa_encrypt
rsa_decrypt
rsa_sign
rsa_verify
rsa_shared_secret
METHODS
new
generate_key
$pk->generate_key($size, $e);
# $size .. (in bytes) 128 - 512
# $e ... 3, 17, 257 or 65537
import_key
export_key_der
export_key_pem
encrypt
my $ct = $pk->encrypt($message);
#or
my $ct = $pk->encrypt($message, $padding);
#or
my $ct = $pk->encrypt($message, 'oaep', $hash_name, $lparam);
# $padding .. 'oaep', 'v1.5' or 'none'
# $hash_name (only for oaep) .. 'SHA1' (DEFAULT), 'SHA256' ...
# $lparam (only for oaep)
decrypt
my $pt = $pk->decrypt($ciphertext);
#or
my $pt = $pk->decrypt($ciphertext, $padding);
#or
my $pt = $pk->decrypt($ciphertext, 'oaep', $hash_name, $lparam);
sign
my $signature = $priv->sign($message);
#or
my $signature = $priv->sign($message, $padding);
#or
my $signature = $priv->sign($message, $padding, $hash_name);
#or
my $signature = $priv->sign($message, $padding, $hash_name, $saltlen);
# $padding .. 'pss' or 'v1.5'
# $hash_name (only for pss) .. 'SHA1' (DEFAULT), 'SHA256' ...
# $saltlen (only for pss) ..... DEFAULT: 12
verify
my $valid = $pub->verify($signature, $message)
#or
my $valid = $pub->verify($signature, $padding, $hash_name);
#or
my $valid = $pub->verify($signature, $padding, $hash_name, $saltlen);