Coding Horror: Why Isn't My Encryption.. Encrypting?
codinghorror.com
codinghorror.com
We give our clients a very simple recommendation when it comes to encrypting things:
* If you're encrypting data in motion, rely on SSL.
* If you're encrypting data at rest, rely on PGP/GPG.
There are plenty of libraries that will GPG a blob for you, and you can assume GPG got all the details right. That would have been the right call here (as opposed to figuring out CBC and --- importantly, for someone who is still fetishizing "salts" in 2009 --- how to safely set an IV).
As an obvious counter example, asymmetric encryption (gpg,et. al) is very slow. Which means that if I need to encrypt a lot of data at rest it sometimes makes sense to use a symmetric cipher.
Security (even just the subdomain of encryption) isn't that easy - there is no one-size-fits all solution.
http://www.gnupg.org/documentation/manuals/gnupg/Operational...
There are a few algorithms to choose from.
Like I posted upthread, there's a laundry list of things that program is going to give you besides picking a better algorithm than "Triple DES" and a better block cipher mode. But listing them is just begging for a bunch of people to propose wack-ass alternative solutions that other people will feel obliged to waste time knocking down.
* you know specifically why SSL/GPG falls short of your requirements
* you realize that algorithms are only a single part of crypto system design
* you know the exact security ramifications of the details (not just "ecb is bad")
* the encryption capabilities are the critical aspect of your whole system (like freenet)
AND
* you accept that your implementation will be broken (at least) several times
But indeed if you know these things, you know that "use SSL/GPG" is good canonical advice.
"copy" "paste"
was it:
1. Don't use ECB (use CBC instead ?)
or
2. Only send data out if you have to (with no mention of the fix to using ECB)
I'm so confused
I found this article interesting even though I've never needed to use encryption explicitly in .NET. I did study crypto in Java, but only briefly whilst in college and we barely touched on ECB. I probably would have made the same mistake and never been the wiser.
Thanks Jeff!
[Edit: Wow, first 0 karma comment in a long time. Must have hit a nerve. My original, and continuing stance on Atwood: http://news.ycombinator.com/item?id=510526]
!!!!!!!
There are two cases when you might want to send sensitive data to the end user: You may wish to send them something and have them send it back in an unmanipulated block, or you may wish to have them manipulate it in some way and send it back to you.
In the first case the best practice is to store the data on the server side and send a pointer (key) to the data. The key is inherently meaningless and sparse relative to its space, and is therefore difficult to attack in any meaningful way.
The second case would rely on the web server sending a piece of (javascript) code to the browser to manipulate the crypto data. If you can see the encrypted text and the plaintext javascript routine you're a trival hack away from rewriting the javascript to have it change the encrypted text. This moves the problem from a crypto problem to a javascript coding exercise. The proper solution in this case is to use a form of crypto that is outside the realm of the HTTP session (read: SSL).
http://news.ycombinator.com/item?id=615446
On how a trivial implementation error (one we're familiar with already) in Debian's OpenSSL means that any message signed with Debian OpenSSL DSA reveals private keys. That's a micro-error; Debian and OpenSSL may have got almost everything else right, but fucked up one tiny detail, and now exposing the ciphertext of certain messages leaks your private key.
This isn't crypto-geek chauvinism. If crypto isn't a big part of what you do in your day-to-day, you're just not going to get this stuff right. That may be the point Jeff is actually trying to make (and the reason he isn't offering a neat solution in his article), but look at the comments on how to "do it right", and you can see that isn't the message that's getting transmitted.
There's a much bigger flaw in Atwood's cryptosystem than has been discussed here --- forget CBC --- but I'm not going to post it, because it will just result in 20 comments about how easy that is to fix, and here's 15 crazy heuristics to do it, so nyah!
In this case, the "salt" is completely irrelevant, because there's no precomputed dictionary you can build for this function.
But I still dispute that a distinction needs to be drawn between the word "salt" and "nonce".
And yeah, his choice of MD5 is an abomination, but that wasn't something that I thought was even nonobvious.