in reply to Encryption 101

You really want to use a module for this:

If you're not familer with the term "salt", just know that it is a random value stored in plaintext with the password. It's there to make brute-force cracking on the password file a lot harder. (A recent program claiming that it could break most WinNT/2k/XP passwords in a few minutes works because Microsoft didn't use salt).

If you're not familer with cryptography in general, I recommend reading through the Cryptogram (external link) archives before using it a lot. Just slapping a module from the Crypt:: namespace isn't enough--you have to use it correctly. As hard as making a secure cipher is, it turns out that it's the easy part. At least creating ciphers has thousands of years of mathmatics behind it so that its security can be anyalized mathmatically. Even a code with theoretically perfect security (like the one-time pad) can be utterly broken if you don't manage your keys correctly, or you use a bad random number generator, or you leave a copy of the plaintext laying around, or . . .

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Re: Re: Encryption 101
by Mr_Person (Hermit) on Aug 01, 2003 at 21:33 UTC
    Why shouldn't MD5 be used for new things? I know there's the problem of possible collisions, but I was under the impression that the real-world chances of that happening were very small. If not MD5, then what hashing function would you recommend?

      Sorry it took so long to reply--I've been on vacation for a week.

      MD5 had its compression function broken. This doesn't hurt its security, but it does mean that one of MD5's design goals is destroyed. IIRC, this also stops MD5 from being used in one of those cute tricks where you use a cryptographic hash as a block cipher (which isn't common, but could be useful in countries where normal encryption is outlawed).

      I haven't read too deeply on the subject, but I know there are other problems with potential collisions that do effect security.

      MD5 isn't dead, but it is bleeding pretty bad. It is intresting to note that both MD5 and SHA1 are very similar to MD4, but SHA1 has subtle changes that make various attacks against MD4 and MD5 impossible.

      In short, use SHA1 if you can. It's not just that has a larger hash value, but its an all-round tougher algorithm.

      ----
      I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
      -- Schemer

      Note: All code is untested, unless otherwise stated

      I think he's overstating "a lot of people". Many seem to preferr SH1 over MD5, but typically this is because of the key length (160bit instead of 128bit) - not because of weaknesses in the algorithm itself. Most people wouldn't try to brute force either. The primary weakness in passwords is almost ALWAYS the fault of those who pick them. Take a look at how 'John the Ripper' works, and you see interesting trends in passwords.