Could you give me guidance on how to proceed.

Your main problem with keeping an encrypted string in your program, is that most encrypted output is binary, and not printable. So.... you will need a technique to base64encode the encrypted output, THEN base64decode the string back to binary, before decryption. Pack and unpack could also be used.

You could also hide your key in plain site, but hidden in your script, like seek to line 42, and grab the 3rd word. :-) Few novices would follow the code to the the key, but its poor security.

Here are the basic techniques. You will find that anyone who knows even a bit of Perl, will be able to hack this. You cannot decrypt a password in a script, without the password being in the script somewhere. You can use RSA keys, to decrypt a key, because the RSA key is in another file, but that depends on home directories, user groups, and permissions setup correctly. Your easiest bet is to use a technique like pack() or MIME_BASE64 to just obscure your key.

#!/usr/bin/perl use warnings; use strict; use Crypt::CBC; use MIME::Base64; my $KEY = 'secret_foo'; my $string = 'yadda yadda yadda yadda'; print "input: $string\n"; my $enc = encryptString( $string ); print "encrypted binary: $enc\n"; my $mime = encode_base64($enc); print "MIME: $mime\n"; my $mime_decode = decode_base64($mime); print "MIME_decode: $mime_decode\n"; my $dec = decryptString( $enc ); print "decrypted: $dec\n"; my $mime_dec = decryptString( decode_base64($mime) ); print "decrypted_mime: $mime_dec\n"; ############################################################ sub encryptString { my $string = shift; my $cipher = Crypt::CBC->new( -key => $KEY, -cipher => 'Blowfish', -padding => 'space', -add_header => 1 ); my $enc = $cipher->encrypt( $string ); return $enc; } ################################################################### sub decryptString { my $string = shift; my $cipher = Crypt::CBC->new( -key => $KEY, -cipher => 'Blowfish', -padding => 'space', -add_header => 1 ); my $dec = $cipher->decrypt( $string ); return $dec; } #############################################################3
And here is a way of obscuring your key with pack(). You could also use encode_base64 to obscure your key.
#!/usr/bin/perl use warnings; use strict; #by fokat of perlmonks my $string = 'justanotherperlhacker'; print "$string\n"; my $obscure = pack("u",$string); print "$obscure\n"; my $unobscure = unpack(chr(ord("a") + 19 + print ""),$obscure); print "$unobscure\n";

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re: Password Encryption and Decryption by zentara
in thread Password Encryption and Decryption by slayedbylucifer

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.