|
Posted by Sisyphus on June 12, 2005, 3:34 pm
Please log in for more thread options
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('DES3',$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 .= "";
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
|