From 88010542443bf1f83906a0bbf7e3003d045471f6 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 7 Jun 2011 15:50:37 +0200 Subject: Raps2/Password: Accept salt for encrypt/decrypt, makes Raps2.pm less messy --- lib/App/Raps2/Password.pm | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'lib/App/Raps2/Password.pm') 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. -=item $pass->encrypt(I) +=item $pass->encrypt(I, [I]) Encrypts I with the passphrase saved in the object, returns the corresponding hexadecimal hash (as string). -=item $pass->decrypt(I) +By default, the salt set in B or B will be used. You can override +it by specifying I. + +=item $pass->decrypt(I, [I]) Decrypts I (as created by B), returns its original content. +By default, the salt set in B or B will be used. You can override +it by specifying I. + =item $pass->bcrypt() Return a base64 bcrypt hash of the password, salted with the salt. -- cgit v1.2.3