Crypt::PK::RSA - Public key cryptography based on RSA
### 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');
$pk->generate_key($size, $e); # $size .. (in bytes) 128 - 512 # $e ... 3, 17, 257 or 65537
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)
my $pt = $pk->decrypt($ciphertext); #or my $pt = $pk->decrypt($ciphertext, $padding); #or my $pt = $pk->decrypt($ciphertext, 'oaep', $hash_name, $lparam);
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
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);
To install CryptX, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CryptX
CPAN shell
perl -MCPAN -e shell install CryptX
For more information on module installation, please visit the detailed CPAN module installation guide.