Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Data File Encryption

by phydeauxarff (Priest)
on Apr 23, 2003 at 13:54 UTC ( #252540=note: print w/replies, xml ) Need Help??

in reply to Data File Encryption

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'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

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://252540]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2023-12-07 07:03 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (32 votes). Check out past polls.