How do you Encrypt and Decrypt a PHP String?

Before you do anything further, seek to understand the difference between encryption and authentication, and why you probably want authenticated encryption rather than just encryption. To implement authenticated encryption, you want to Encrypt then MAC. The order of encryption and authentication is very important! One of the existing answers to this question made this mistake; … Read more

Java 256-bit AES Password-Based Encryption

Share the password (a char[]) and salt (a byte[]—8 bytes selected by a SecureRandom makes a good salt—which doesn’t need to be kept secret) with the recipient out-of-band. Then to derive a good key from this information: /* Derive the key, given password and salt. */ SecretKeyFactory factory = SecretKeyFactory.getInstance(“PBKDF2WithHmacSHA256”); KeySpec spec = new PBEKeySpec(password, … Read more

Encrypt and decrypt a string in C#? [closed]

EDIT 2013-Oct: Although I’ve edited this answer over time to address shortcomings, please see jbtule’s answer for a more robust, informed solution. https://stackoverflow.com/a/10366194/188474 Original Answer: Here’s a working example derived from the “RijndaelManaged Class” documentation and the MCTS Training Kit. EDIT 2012-April: This answer was edited to pre-pend the IV per jbtule’s suggestion and as … Read more