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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • saysuri
    New Member
    • Aug 2013
    • 7

    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:



    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:
    Code:
    use Crypt::Mode::CBC;
     
    my $key = '(32bit key value)'; 
    my $iv = '(32bit iv value)';
    my $cbc = Crypt::Mode::CBC->new('AES');
    my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
    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

    Code:
    use Crypt::CBC;
    use Crypt::Cipher::AES;
    
    my $key = '(32bit key value)'; 
    my $iv = '(32bit iv value)';
    my $cbc = Crypt::CBC->new( -cipher=>'Cipher::AES', -key=>$key, -iv=>$iv );
    my $ciphertext = $cbc->encrypt("secret data");
    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...
    Last edited by saysuri; Aug 29 '13, 10:26 AM. Reason: some more additional information like code used.
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    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

    Comment

    • saysuri
      New Member
      • Aug 2013
      • 7

      #3
      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...

      Comment

      • saysuri
        New Member
        • Aug 2013
        • 7

        #4
        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

        Comment

        • saysuri
          New Member
          • Aug 2013
          • 7

          #5
          So Finally revised code:

          Code:
             
          
              use Crypt::Mode::CBC;
               
              my $key = '(32bit key value)'; 
              my $iv = '(16 bit iv plain string value)';
              my $cbc = Crypt::Mode::CBC->new('AES');
              my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
              print $ciphertext;
              my $plaintext = $cbc->decrypt($ciphertext, $key, $iv);
              print $plaintext;

          Comment

          • numberwhun
            Recognized Expert Moderator Specialist
            • May 2007
            • 3467

            #6
            I assume all is working ok now?

            Comment

            • saysuri
              New Member
              • Aug 2013
              • 7

              #7
              Yes it's working normal as expected.

              Comment

              Working...