<t>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.<br/>
<br/>
https://stackoverflow.com/a/10366194/188474<br/>
<br/>
Original Answer:<br/>
<br/>
Here's a working example derived from the "RijndaelManaged Class" documentation and the MCTS Training Kit. <br/>
<br/>
EDIT 2012-April: This answer was edited to pre-pend the IV per jbtule's suggestion and as illustrated here:<br/>
<br/>
http://msdn.microsoft.com/en-us/library/system.security.cryptography.aesmanaged%28v=vs.95%29.aspx<br/>
<br/>
Good luck!<br/>
<br/>
public class Crypto<br/>
{<br/>
<br/>
//While an app specific salt is not the best practice for<br/>
//password based encryption, it's probably safe enough as long as<br/>
//it is truly uncommon. Also too much work to alter this answer otherwise.<br/>
private static byte[] _salt = __To_Do__("Add a app specific salt here");<br/>
<br/>
/// <br/>
/// Encrypt the given string using AES. The string can be decrypted using <br/>
/// DecryptStringAES(). The sharedSecret parameters must match.<br/>
/// <br/>
/// The text to encrypt.<br/>
/// A password used to generate a key for encryption.<br/>
public static string EncryptStringAES(string plainText, string sharedSecret)<br/>
{<br/>
if (string.IsNullOrEmpty(plainText))<br/>
throw new ArgumentNullException("plainText");<br/>
if (string.IsNullOrEmpty(sharedSecret))<br/>
throw new ArgumentNullException("sharedSecret");<br/>
<br/>
string outStr = null; // Encrypted string to return<br/>
RijndaelManaged aesAlg = null; <br/>
<br/>
*(Réponse tronquée)*</t>