Here's a little script that I put together to help you get going. Instead of SHA1, I use SHA-256---for me, it's better and stronger than SHA1; also, for AES-128-ECB, I used Crypt::CBC with a Rijndael cipher in MODE_ECB, rijndael_compat. Give it a try.
#!/usr/bin/perl -l use strict; use warnings; use CPAN; use Crypt::CBC; use Crypt::Rijndael; use Data::Translate; use Data::Dumper::Concise; use MIME::Base64 qw(encode_base64); use Digest::SHA qw(sha256_hex sha256_base64); $| = 1; CPAN::Shell->install(qw( Crypt::CBC Crypt::Rijndael Data::Translate Data::Dumper::Concise Digest::SHA MIME::Base64)); print "=" x 72; print "Converting ascii to hex: "; my $data = new Data::Translate; my @aa = qw(hello_world); my ( $s, @ah ) = $data->a2h(@aa); binmode STDOUT, ":encoding(utf8)"; print "\t", join( '', @ah ); print "=" x 72; print "Converting hex to ascii:"; my $data2 = new Data::Translate; my @hh = qw(68 65 6c 6c 6f 5f 77 6f 72 6c 64); my ( $s2, @ha2 ) = $data2->h2a(@hh); binmode STDOUT, ":encoding(utf8)"; print "\t", join( '', @ha2 ); print "=" x 72; print "Calculating sha256_hex digest for hex: "; my $data3 = '68 65 6c 6c 6f 5f 77 6f 72 6c 64'; print "\t", sha256_hex($data3); print "=" x 72; print "Calculating sha256_hexdigest for hello_world: "; my $data4 = qw(hello_world); print "\t", sha256_hex($data4); print "=" x 72; print "Calculating sha256_base64 for hello_world: "; my $data5 = qw(hello_world); local ($/) = undef; print "\t", encode_base64($data5); print "=" x 72; my $bs = Crypt::Rijndael->blocksize; my $ks = Crypt::Rijndael->keysize; my $cipher = Crypt::CBC->new( -key => 'a' x $ks, -iv => 'f' x $bs, -literal_key => 1, -cipher => 'Rijndael', -header => 'none', -padding => 'rijndael_compat', ); my $in = <<"END"; hello_world END my $j = Crypt::Rijndael->new( 'a' x $ks, Crypt::Rijndael->MODE_ECB ); $j->set_iv( 'f' x $bs ); $cipher->start('encrypting'); if ($in) { my $string = 'a' x 32; binmode STDOUT, ":encoding(UTF-8)"; my $encrypt = $cipher->encrypt($string); my $decrypt = $cipher->decrypt($encrypt); print "Testing MODE_ECB: "; print "\t", Dumper("$decrypt"); } $cipher->finish;

References:

Crypt::CBC
Crypt::Rijndael
Data::Translate
Data::Dumper::Concise
MIME::Base64
Digest::SHA


In reply to Re: generating an encoded text by Khen1950fx
in thread generating an encoded text by shekarkcb

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.