summaryrefslogtreecommitdiff
path: root/lib/App/Raps2/Password.pm
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-06-07 15:50:37 +0200
committerDaniel Friesel <derf@finalrewind.org>2011-06-07 15:50:37 +0200
commit88010542443bf1f83906a0bbf7e3003d045471f6 (patch)
treebd13f1ce0f9a91b8f1853ea4b4c7c470a0e7af65 /lib/App/Raps2/Password.pm
parentf4d7e354367d78f36024255ca598431e3508005e (diff)
Raps2/Password: Accept salt for encrypt/decrypt, makes Raps2.pm less messy
Diffstat (limited to 'lib/App/Raps2/Password.pm')
-rw-r--r--lib/App/Raps2/Password.pm26
1 files changed, 18 insertions, 8 deletions
diff --git a/lib/App/Raps2/Password.pm b/lib/App/Raps2/Password.pm
index 1a3ab63..3662c29 100644
--- a/lib/App/Raps2/Password.pm
+++ b/lib/App/Raps2/Password.pm
@@ -59,20 +59,24 @@ sub salt {
}
sub encrypt {
- my ( $self, $in ) = @_;
+ my ( $self, $in, $salt ) = @_;
- my $eksblowfish = Crypt::Eksblowfish->new( $self->{cost}, $self->{salt},
- $self->{passphrase}, );
+ $salt //= $self->{salt};
+
+ my $eksblowfish
+ = Crypt::Eksblowfish->new( $self->{cost}, $salt, $self->{passphrase}, );
my $cbc = Crypt::CBC->new( -cipher => $eksblowfish );
return $cbc->encrypt_hex($in);
}
sub decrypt {
- my ( $self, $in ) = @_;
+ my ( $self, $in, $salt ) = @_;
+
+ $salt //= $self->{salt};
- my $eksblowfish = Crypt::Eksblowfish->new( $self->{cost}, $self->{salt},
- $self->{passphrase}, );
+ my $eksblowfish
+ = Crypt::Eksblowfish->new( $self->{cost}, $salt, $self->{passphrase}, );
my $cbc = Crypt::CBC->new( -cipher => $eksblowfish );
return $cbc->decrypt_hex($in);
@@ -169,15 +173,21 @@ Returns a new 16-byte salt. Contains only printable characters.
Returns the currently used salt and optionally changes it to I<salt>.
-=item $pass->encrypt(I<data>)
+=item $pass->encrypt(I<data>, [I<salt>])
Encrypts I<data> with the passphrase saved in the object, returns the
corresponding hexadecimal hash (as string).
-=item $pass->decrypt(I<hexstr>)
+By default, the salt set in B<salt> or B<new> will be used. You can override
+it by specifying I<salt>.
+
+=item $pass->decrypt(I<hexstr>, [I<salt>])
Decrypts I<hexstr> (as created by B<encrypt>), returns its original content.
+By default, the salt set in B<salt> or B<new> will be used. You can override
+it by specifying I<salt>.
+
=item $pass->bcrypt()
Return a base64 bcrypt hash of the password, salted with the salt.