Cryptology is such a broad subject that even experienced coders will almost always make mistakes the first few times around.  However encryption is such an important topic, often we can't afford to have these mistakes. 

The intent of this question is to identify and list what not to do with a given algorithm or API.  This way we can learn from other's experiences and prevent the spread of bad practices.

To keep this question constructive, please 


Include a "wrong" example
Explain what is wrong with that example
Provide a correct implementation (if applicable). 
To the best of your ability, provide references regarding #2 and #3 above.


Don't roll your own crypto.

Don't invent your own encryption algorithm or protocol; that is extremely error-prone.  As Bruce Schneier likes to say, 


  "Anyone can invent an encryption algorithm they themselves can't break; it's much harder to invent one that no one else can break".  


Crypto algorithms are very intricate and need intensive vetting to be sure they are secure; if you invent your own, you won't get that, and it's very easy to end up with something insecure without realizing it.

Instead, use a standard cryptographic algorithm and protocol.  Odds are that someone else has encountered your problem before and designed an appropriate algorithm for that purpose.

Your best case is to use a high-level well-vetted scheme: for communication security, use TLS (or SSL); for data at rest, use GPG (or PGP).  If you can't do that, use a high-level crypto library, like cryptlib, GPGME, Keyczar, or NaCL, instead of a low-level one, like OpenSSL, CryptoAPI, JCE, etc..  Thanks to Nate Lawson for this suggestion.
