diff options
Diffstat (limited to 'lib/App/Raps2')
-rw-r--r-- | lib/App/Raps2/Password.pm | 26 |
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. |