Further to ikegami's answer, not only does Crypt::CBC make things easier for you, it is also a lot more secure than manually encrypting the data in 8-byte chunks, because it XOR's each block with the preceding block, thus making it harder to spot data patterns (this doesn't matter much for small pieces of data like passwords, but is good to keep in mind in general).

Also, if you want any kind of real security:

  1. Don't use passwords with less than eight characters
  2. Don't use DES, it has known weaknesses and should no longer be used for any serious encryption. Crypt::CBC also works with lots of stronger ciphers, such as Crypt::IDEA, Crypt::Blowfish or Crypt::Rjindael (just substitute -cipher => 'DES' in ikegami's code with -cipher => 'Blowfish' and make sure you have the relevant module installed).Update: I see ikegami has added an update with the same recommendation while I was typing mine. I'll type quicker next time :-)

There are ten types of people: those that understand binary and those that don't.

In reply to Re: how to crypt and decrypt password from 4 to 15 characters in length by tirwhan
in thread how to crypt and decrypt password from 4 to 15 characters in length by bengmau

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.