Skip to content

Instantly share code, notes, and snippets.

@jmeridth
Created December 14, 2009 12:43
Show Gist options
  • Save jmeridth/256019 to your computer and use it in GitHub Desktop.
Save jmeridth/256019 to your computer and use it in GitHub Desktop.
C# rijdael test
[Test]
public void rijndael_test()
{
var rijndaelAlg = Rijndael.Create();
byte[] data = Encoding.UTF8.GetBytes("1234567890abcdef");
rijndaelAlg.Key = new ASCIIEncoding().GetBytes("pass123pass123pass123pass123pass");
rijndaelAlg.IV = new ASCIIEncoding().GetBytes("1234567890abcdef");
using (var memoryStream = new MemoryStream())
using (var cryptoStream = new CryptoStream(memoryStream, rijndaelAlg.CreateEncryptor(), CryptoStreamMode.Write))
{
cryptoStream.Write(data, 0, data.Length);
cryptoStream.FlushFinalBlock();
var cipherTextBytes = memoryStream.ToArray();
Console.WriteLine(Convert.ToBase64String(cipherTextBytes));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment