0

I'm trying to generate a public and private key with passphrase protection in Perl but I haven't found anything useful.

Until now I have found this link http://search.cpan.org/~vipul/Crypt-RSA-1.57/lib/Crypt/RSA.pm which seems very promising. However, I can decrypt my message without any passphrase although I have created them with a passphrase.

The other link was this http://www.perlmonks.org/?node_id=903458 but when I create my keys (in order to store them in the DB) I still can decrypt without using a passphrase.

In summary, I need a library which allows me to encrypt text using private keys using a passphrase for both.

Thanks for your help!

PD: Please no PGP encryption.

UPDATE

Here is a pice of code that does not work as expected:

use strict;
use warnings;
use Data::Dumper;
use 5.010;
use Crypt::RSA;

my $rsa = new Crypt::RSA;

my ($master_public, $master_private) = $rsa->keygen(
   Identity => "Someone",
   Size     => 1024,
   Password => "this is a password or passphare",
) or die $rsa->errstr();

my $cyphertext = $rsa->encrypt (
   Message    => "My Message that I want to encrypt",
   Key        => $master_public,
   Armour     => 1,
) or die $rsa->errstr();

my $text = $rsa->decrypt (
    Cyphertext => $cyphertext,
    Key        => $master_private,
    Armour     => 1,
    # Here I expect to add the user's passphrase
) or die $rsa->errstr();

say $text;
Ramzendo
  • 576
  • 1
  • 5
  • 16
  • Please add a snippet of the *actual Perl code* that you believe demonstrates the ability to "decrypt encrypted content without a pass-phrase." Be as *specific* as possible. – Mike Robinson Jun 29 '16 at 13:11
  • Hi Mike, I added a snippet to prove my point. Thanks! – Ramzendo Jun 29 '16 at 13:25

1 Answers1

2

The passphrase for RSA is only used in regards to saving or reading the key on disk. At no point in your operation did you save the private key to disk so it is already unencrypted in memory.

From the private key documentation, you can see how to hide and save it to disc (the $master_private object you have is already an object of that type)

https://metacpan.org/pod/Crypt::RSA::Key::Private

Tim Tom
  • 779
  • 3
  • 6