469,336 Members | 5,230 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

How to do encryption in perl with aes-128-cbc

Hi All,

once Again back with one more question.

can some one please help me how to use aes-128-cbc in perl.
I got the information like:

https://metacpan.org/module/Crypt::O...Cipher::AES128

but How can i use this in encrypting in perl.


I got some data,key and iv values and i need to encrypt it using the aes-128-cbc.


Here is some more additional information:
Expand|Select|Wrap|Line Numbers
  1. use Crypt::Mode::CBC;
  2.  
  3. my $key = '(32bit key value)'; 
  4. my $iv = '(32bit iv value)';
  5. my $cbc = Crypt::Mode::CBC->new('AES');
  6. my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
  7. print $ciphertext;
after executing the above code it is showing the error message as :

Uncaught exception from user code:

Can't locate loadable object for module CryptX in @INC (@INC contains: C
:/Dwimperl/perl/site/lib C:/Dwimperl/perl/vendor/lib C:/Dwimperl/perl/lib .) at
C:/Dwimperl/perl/site/lib/Crypt/Cipher.pm line 5
Compilation failed in require at C:/Dwimperl/perl/site/lib/Crypt/Cipher.pm line
5.
BEGIN failed--compilation aborted at C:/Dwimperl/perl/site/lib/Crypt/Cipher.pm l
ine 5.
Compilation failed in require at C:/Dwimperl/perl/site/lib/Crypt/Mode/CBC.pm lin
e 8.
BEGIN failed--compilation aborted at C:/Dwimperl/perl/site/lib/Crypt/Mode/CBC.pm
line 8.
Compilation failed in require at cipher1.pl line 1.
BEGIN failed--compilation aborted at cipher1.pl line 1.
at cipher1.pl line 1
Press any key to continue . . .

-----------------------------------------------------
or

Expand|Select|Wrap|Line Numbers
  1. use Crypt::CBC;
  2. use Crypt::Cipher::AES;
  3.  
  4. my $key = '(32bit key value)'; 
  5. my $iv = '(32bit iv value)';
  6. my $cbc = Crypt::CBC->new( -cipher=>'Cipher::AES', -key=>$key, -iv=>$iv );
  7. my $ciphertext = $cbc->encrypt("secret data");
  8. print $ciphertext;
after executing the above code it is showing the error message as :

Uncaught exception from user code:
Can't locate loadable object for module CryptX in @INC (@INC contains: C
:/Dwimperl/perl/site/lib C:/Dwimperl/perl/vendor/lib C:/Dwimperl/perl/lib .) at
C:/Dwimperl/perl/site/lib/Crypt/Cipher/AES.pm line 8
Compilation failed in require at C:/Dwimperl/perl/site/lib/Crypt/Cipher/AES.pm l
ine 8.
BEGIN failed--compilation aborted at C:/Dwimperl/perl/site/lib/Crypt/Cipher/AES.
pm line 8.
Compilation failed in require at cipher2.pl line 2.
BEGIN failed--compilation aborted at cipher2.pl line 2.
at cipher2.pl line 2
Press any key to continue . . .

-------------------------------------------------------
In this case can some one please do let me know how can i check if 'CryptX' and (related modules) are installed properly in my machine.


Thanks in adv...
Aug 29 '13 #1

✓ answered by numberwhun

It looks like module CryptX is needed by the module your using. I don't know how you are installing modules, but if your using CPAN, then you may want to turn on "follow" for how to install dependencies. That way anything needed by the module is automatically installed when you install the module you want.

Regards,

Jeff

6 6029
numberwhun
3,503 Expert Mod 2GB
It looks like module CryptX is needed by the module your using. I don't know how you are installing modules, but if your using CPAN, then you may want to turn on "follow" for how to install dependencies. That way anything needed by the module is automatically installed when you install the module you want.

Regards,

Jeff
Aug 29 '13 #2
Dear Jeff,

thanks for the replay.
just found, how to do that one and did it.

now how to install the module(cryptx) in win 32 bit machine...
Aug 30 '13 #3
Dear Jeff,

Thanks for the information. Actualy my vi key is in 32 bit and so it showed up some error askign for 16 block.

I tried tried converting hex to 16 bit string and then used in the code.
Finally it worked & all is well and all happies.

once again thanks for the information.
you made my day, waiting for this since last 2 days
Aug 30 '13 #4
So Finally revised code:

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.  
  4.     use Crypt::Mode::CBC;
  5.  
  6.     my $key = '(32bit key value)'; 
  7.     my $iv = '(16 bit iv plain string value)';
  8.     my $cbc = Crypt::Mode::CBC->new('AES');
  9.     my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
  10.     print $ciphertext;
  11.     my $plaintext = $cbc->decrypt($ciphertext, $key, $iv);
  12.     print $plaintext;
  13.  
  14.  
  15.  
Aug 30 '13 #5
numberwhun
3,503 Expert Mod 2GB
I assume all is working ok now?
Aug 31 '13 #6
Yes it's working normal as expected.
Aug 31 '13 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Hal Vaughan | last post: by
4 posts views Thread by Piotr Turkowski | last post: by
1 post views Thread by Marshall Dudley | last post: by
3 posts views Thread by DGG | last post: by
1 post views Thread by Babu | last post: by
1 post views Thread by josh.kuo | last post: by
4 posts views Thread by Olle24 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by haryvincent176 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.