Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??
Welcome to the world of encryption, we can share our secrets wtih you but then we will have to kill you ;-)

Seriously, if you are wanting to learn more about encryption I would highly recommend picking up Applied Cryptography: Protocols, Algorithms, and Source Code in C by Bruce Schneier at some point...

Yes, I know...it's not a perl book but it is an excellent resource on cryptography programming as evidenced by the well used copy I keep borrowing from DrManhattan

For your specific application, are you wanting to use symmetric encryption...say, to store a file away from prying eyes. Or, do you need something asymmetric like PGP to send an encrypted file...i.e. an e-mail to someone so they can decrypt it?

If you are wanting symmetric encryption of a file, then Crypt::CBC is a breeze...

To Encrypt using Blowfish...

#! /usr/bin/perl use Crypt::CBC; $cipher = Crypt::CBC->new( {'key' => 'my secret key', 'cipher' => 'Blowfish', 'iv' => '$KJh#(}q', 'regenerate_key' => 0, # default true 'padding' => 'space', 'prepend_iv' => 0 }); $cipher->start('encrypting'); open(F,"./plain_file"); open(STDOUT,">crypt_file"); while (read(F,$buffer,1024)) { print $cipher->crypt($buffer); } close STDOUT;
And to decrypt...
$cipher->start('decrypting'); open(F,"./crypt_file"); while (read(F,$buffer,1024)) { print $cipher->crypt($buffer); }

That should get you started


In reply to Re: Data File Encryption by phydeauxarff
in thread Data File Encryption by Jamnet

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.