Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

which crypt:: ?

by silent11 (Vicar)
on Feb 01, 2003 at 13:50 UTC ( [id://231842]=perlquestion: print w/replies, xml ) Need Help??

silent11 has asked for the wisdom of the Perl Monks concerning the following question:

I have no experience with cryptology. I'm seeking a module that would allow me to encrypt and decrypt a string by the same key.
I have used Digest::MD5 for mixing up some data to create a semi-unique identifier to be used as a cookie value (CGI Programming 2nd Edition), however after reading the Digest::MD5 doc I'm not sure if that module would be of any help for this chore.

Any (thoughts|tips|tricks) would be greatly appreciated.

-Silent11

Replies are listed 'Best First'.
Re: which crypt:: ?
by fokat (Deacon) on Feb 01, 2003 at 14:21 UTC

    None of the Digest:: modules will serve your purpose, as those are geared towards producing a Digest. What you're looking at is called Symmetric Crypt. You can probably use Crypt::DES_EDE3 or Crypt::Blowfish (those are the ones that I would consider).

    Make sure you read the documentation for the modules thoroughly. I only have sueprficial training in cryptography...

    Best regards

    -lem, but some call me fokat

Re: which crypt:: ?
by zentara (Archbishop) on Feb 01, 2003 at 14:47 UTC
    What are you trying to do? Encrypt a cookie? If that's the case, then you can use any of the Crypt modules, but you want to use Mime::Base64 on it, so it can pass thru the web. Here is an example for Crypt::RC4. The nice thing about RC4 is that it has a pure perl module which you can upload to your server, if they don't have it installed. It's fast, although not the best security(but who are you trying to hide from anyways? It's probably not secure from the government)
    #!/usr/bin/perl use strict; use warnings; use Crypt::RC4; use MIME::Base64; my $key = "abcdefghijklm"; my $plaintext = "Hello, World!"; my $encrypted = RC4($key, $plaintext); my $encoded = encode_base64($encrypted); my $decoded = decode_base64($encoded); print "$encoded\n"; print "$decoded\n"; my $decrypted = RC4($key, $decoded); print "$decrypted\n";

      With a stream cipher like RC4, it's extremely important that you NEVER ENCRYPT TWO MESSAGES WITH THE SAME KEY. If you do, the security reduces to that of simple xor encryption -- in other words, no security at all. This problem is mentioned in the Crypt::RC4 docs. Using a string hardcoded into your script as the key is the wrong way to use this module.

      If you want an out-of-the-box encryption solution, I would recommend Crypt::CBC. There are pure-perl encryption modules you can use with it, if compiling modules is a problem for you.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://231842]
Approved by mattriff
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-19 06:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found