<p><strong>EDIT 2013-Oct</strong> : Bien que nous ayons modifie cette reponse au fil du temps pour corriger les lacunes, veuillez consulter <a href="https://stackoverflow.com/a/10366194/157247">la reponse de jbtule</a> pour une solution plus robuste et mieux informee.</p>
<p><a href="https://stackoverflow.com/a/10366194/188474">https://stackoverflow.com/a/10366194/188474</a></p>
<p><strong>Reponse originale :</strong></p>
<p>Voici un exemple fonctionnel derive de la <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.rijndaelmanaged%28v=VS.90%29.aspx">documentation de la classe “RijndaelManaged”</a> et du <a href="https://rads.stackoverflow.com/amzn/click/com/0735626197">kit de formation MCTS</a>.</p>
<p><strong>EDIT 2012-Avril</strong> : Cette reponse a ete modifiee pour prefixer l’IV selon la suggestion de jbtule et comme illustre ici :</p>
<p><a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.aesmanaged%28v=vs.95%29.aspx">http://msdn.microsoft.com/en-us/library/system.security.cryptography.aesmanaged%28v=vs.95%29.aspx</a></p>
<p>Bonne chance !</p>
<pre><code class="lang-auto">public class Crypto
{
//While an app specific salt is not the best practice for
//password based encryption, it's probably safe enough as long as
//it is truly uncommon. Also too much work to alter this answer otherwise.
private static byte[] _salt = __To_Do__("Add a app specific salt here");
/// <summary>
/// Encrypt the given string using AES. The string can be decrypted using
/// DecryptStringAES(). The sharedSecret parameters must match.
/// </summary>
/// <param name="plainText">The text to encrypt.</param>
/// <param name="sharedSecret">A password used to generate a key for encryption.</param>
public static string EncryptStringAES(string plainText, string sharedSecret)
{
if (string.IsNullOrEmpty(plainText))
throw new ArgumentNullException("plainText");
if (string.IsNullOrEmpty(sharedSecret))
throw new ArgumentNullException("sharedSecret");
string outStr = null; // Encrypted string to return
RijndaelManaged aesAlg = null;
</code></pre>
<p><em>(Reponse tronquee)</em></p>