Net::SSH::Perl::Cipher Problem.

Net::SSH::Perl::Cipher Problem.

am 10.06.2005 09:51:57 von Prasad

I am using the following script. Its encrypting the data but when i
decrypt, i am not getting the original text again.


use Net::SSH::Perl::Cipher;
$key =3D "0123456789ABCDEF12345678";
$plaintext=3D"Shankar";
my $cipher =3D Net::SSH::Perl::Cipher->new('D=ADES3',$key);
my $ciphertext =3D $cipher->encrypt($plaintext);
print "The Plain text is : [$plaintext]\n";
print "The Cipher is : [$cipher]\n";
print "The Cipher text is : [$ciphertext] \n";
my $recoveredtext =3D $cipher->decrypt($ciphertext);
print "The recovered text is : [$recoveredtext]\n";


Output
The Plain text is : [Shankar]
The Cipher is : [Net::SSH::Perl::Cipher::DES3=­HASH(0x708fc)]
The Cipher text is : [莋ϪþqK]
The recovered text is : [Üdh´¢¶·]=20


Thanks in Advance.

Re: Net::SSH::Perl::Cipher Problem.

am 12.06.2005 06:34:04 von Sisyphus

"Prasad" wrote in message
news:1118389917.659713.113550@o13g2000cwo.googlegroups.com.. .
I am using the following script. Its encrypting the data but when i
decrypt, i am not getting the original text again.


use Net::SSH::Perl::Cipher;
$key = "0123456789ABCDEF12345678";
$plaintext="Shankar";
my $cipher = Net::SSH::Perl::Cipher->new('D­ES3',$key);
my $ciphertext = $cipher->encrypt($plaintext);
print "The Plain text is : [$plaintext]\n";
print "The Cipher is : [$cipher]\n";
print "The Cipher text is : [$ciphertext] \n";
my $recoveredtext = $cipher->decrypt($ciphertext);
print "The recovered text is : [$recoveredtext]\n";


Output
The Plain text is : [Shankar]
The Cipher is : [Net::SSH::Perl::Cipher::DES3=­HASH(0x708fc)]
The Cipher text is : [èZ<ϪþqK]
The recovered text is : [Üdh´¢¶·]
---------------------------------------------------

Don't forget to 'use warnings;'.

Could it be that $plaintext needs to be 8 (or a multiple of 8) bytes long ?
It shouldn't matter, but as a test try with:
$plaintext = 'Shankar1";

I don't have this module so am unable to test it out myself. I was, however,
able to run the following script:

use warnings;
use Crypt::DES_EDE3;
$key = "0123456789ABCDEF12345678";
$plaintext="Shankar";
$plaintext .= "\0";
my $cipher = Crypt::DES_EDE3->new($key);
my $ciphertext = $cipher->encrypt($plaintext);
print "The Plain text is : [$plaintext]\n";
print "The Cipher is : [$cipher]\n";
print "The Cipher text is : [$ciphertext] \n";
my $recoveredtext = $cipher->decrypt($ciphertext);
print "The recovered text is : [$recoveredtext]\n";

That produced the following for me:

The Plain text is : [Shankar ]
The Cipher is : [Crypt::DES_EDE3=HASH(0x3f5060)]
The Cipher text is : [èZ<ϪþqK]
The recovered text is : [Shankar ]

I think that demonstrates that the Net::SSH::Perl encryption subroutine is
functioning correctly (assuming that null-padding is the appropriate
action), but that there's something amiss with the Net::SSH::Perl decryption
subroutine.

Cheers,
Rob