Hi,
I am trying write a module for encrypt and decrypt. And in my main perl program , i would like to call the encrypt and decrypt method. First time i am writing a module. So can any one help me to do how should i call the encrypt and decrypt function.
Following are my module code

package Config::Confmanager; use Exporter; #export all the methods @EXPORT=qw(&Encrypt,&Decrypt); use warnings; use strict "refs"; use Crypt::CBC; #CPAN Module For Encryption And Decryption #Creating Constructor; sub new { my($self) = {}; bless ($self); return ($self); } #--------------------------------------------------------------------- +---------------------------------------- #Encrypt And Decrypt Method #--------------------------------------------------------------------- +--------------------------------------- sub CreateEncryptDecryptObject { $cipher = Crypt::CBC->new( {'key' => 'passport', 'cipher' => 'DES', 'iv' => '$KJh#(}q', 'regenerate_key' => 0, # default true 'padding' => 'space', 'prepend_iv' => 0 }); } #--------------------------------------------------------------------- +---------------------------------------- #Encrypt Method #Takes An Option Value As Plain String And Encrypts It #--------------------------------------------------------------------- +--------------------------------------- sub Encrypt { CreateEncryptDecryptObject(); my($encryptstring) = @_; my $cipherencryptstring = $cipher->encrypt($encryptstring); if (!$cipherencryptstring) { $log->error("Could not Encrypt requested string\n",); return ; } else { return($cipherencryptstring); } } #--------------------------------------------------------------------- +------------------------------------------- # End Of Encrypt Method #--------------------------------------------------------------------- +--------------------------------------------- #--------------------------------------------------------------------- +---------------------------------------- #Decrypt Method #Takes An Encrypted String And Decrypts It #--------------------------------------------------------------------- +--------------------------------------- sub Decrypt { CreateEncryptDecryptObject(); my($decryptstring) = @_; my $cipherdecryptstring = $cipher->decrypt($decryptstring); if (!$cipherdecryptstring) { $log->error("Could not Decrypt requested string\n",); exit; } else { return($cipherencryptstring); } } 1; #--------------------------------------------------------------------- +------------------------------------------- # End Of Decrypt Method #--------------------------------------------------------------------- +------------------------------------------- #--------------------------------------------------------------------- +------------------------------------------ =head1 NAME cut #--------------------------------------------------------------------- +------------------------------------------


Main program i would like to call Encrypt and decrypt mehtod and pass the string.
Help me
Regards,
Jh

janitored by ybiC: Balanced <readmore> tags around longish codeblock, to reduce vertical scrolling


In reply to How to call Module by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.