Skip to content

Instantly share code, notes, and snippets.

@ssukhpinder
Created September 19, 2020 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssukhpinder/738b4617ede24cef163de149c7fd24ba to your computer and use it in GitHub Desktop.
Save ssukhpinder/738b4617ede24cef163de149c7fd24ba to your computer and use it in GitHub Desktop.
FileStream myStream = new FileStream("TestData.txt", FileMode.OpenOrCreate);
Aes aes = Aes.Create();
byte[] key = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };
byte[] iv = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };
CryptoStream cryptStream = new CryptoStream(
myStream,
aes.CreateEncryptor(key, iv),
CryptoStreamMode.Write);
StreamWriter sWriter = new StreamWriter(cryptStream);
sWriter.WriteLine("Hello World!");
sWriter.Close();
cryptStream.Close();
myStream.Close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment