Crypt::RSA::Simple - Encrypts/decrypts text with RSA keys
use Crypt::RSA::Simple;
my $crypt = Crypt::RSA::Simple->new(
key_dir => '/home/user/keys',
key_size => 2048,
private_key => 'secure_key.priv',
public_key => 'secure_key.pub',
);
$crypt->generate()
Or it can be fed with method arguments:
my $crypt = Crypt::RSA::Simple->new();
$crypt->generate(
'/home/user/keys',
2048,
'secure_key.priv',
'secure_key.pub'
);
Private and public keys can be set with their getter/setter methods as well as the key_dir and key_size:
my $crypt->private_key( '/home/user/keys/secret.priv' );
my $crypt->public_key( '/home/user/keys/secret.pub' );
my $crypted = $crypt->encrypt( 'text to crypt' );
my $encrypted = $crypt->decrypt( $crypted );
Or keys can be used with the crypt
and decrypt
methods as their arguments as well:
my $decrypted = $crypt->decrypt(
'encrypted text',
'/home/user/keys/secret.priv'
);
Class methods and instance methods are both supported:
Crypt::RSA::Simple->encrypt( 'text', '/home/user/keys/secret.pub' );
Crypt::RSA::Simple is just a tiny but flexible wrapper on the top of the Crypt::OpenSSL::RSA
library. It encrypts and decrypts any text, and it can generate RSA keys if necessary.
This tool does not give any new features to the original module, rather it wraps it into an easy-to-use form. It offers an elegant, pure Perl OO interface.
It uses MIME::Base64
to encode/decode the crypted text, makes it easier to store it on a drive e.g. in a file.
- new:
-
Creates a new Crypt::RSA::Simple object instance
Arguments:
key_dir
: Path to the key directory (String)key_size
: Key size for key generation (Integer)private_key
: Name of the key (String)public_key
: Name of the key (String)All parameters can be set with getter/setter methods
- private_key:
-
Getter/setter method for the private key
- public_key:
-
Getter/setter method for the public key
- key_dir:
-
Getter/setter method for the key directory
- key_size:
-
Getter/setter method for the key size
- generate:
-
Method for private and public key generation
Arguments:
key_dir
: Path to the key directory (String)key_size
: Key size for key generation (Integer)private_key
: Name of the key (String)public_key
: Name of the key (String)This method generates a key pair into the
key_dir
to encrypt and decrypt with. If it is called without arguments it uses the default values. - encrypt
-
Method for text encrytion
Arguments:
text
: Text to be encrypted (String)public_key
: Public key for encryption (String) - decrypt
-
Method for decrypting ecrypted text
Arguments:
text
: Text to be decrypted (String)private_key
: Private key for encryption (String)
Tamas Molnar <[email protected]>
Copyright 2016, Tamas Molnar
This library is free software; you may redistribute it and/or modify it under the same terms as Perl itself.