public static byte[] Encrypt(byte[] input) { PasswordDeriveBytes pdb = new PasswordDeriveBytes("hjiweykaksd", // Change this new byte[] { 0x43, 0x87, 0x23, 0x72}); // Change this MemoryStream ms = new MemoryStream(); Aes aes = new AesManaged(); aes.Key = pdb.GetBytes(aes.KeySize / 8); aes.IV = pdb.GetBytes(aes.BlockSize / 8); CryptoStream cs = new CryptoStream(ms, aes.CreateEncryptor(), CryptoStreamMode.Write); cs.Write(input, 0, input.Length); cs.Close(); return ms.ToArray(); } public static byte[] Decrypt(byte[] input) { PasswordDeriveBytes pdb = new PasswordDeriveBytes("hjiweykaksd", // Change this new byte[] { 0x43, 0x87, 0x23, 0x72}); // Change this MemoryStream ms = new MemoryStream(); Aes aes = new AesManaged(); aes.Key = pdb.GetBytes(aes.KeySize / 8); aes.IV = pdb.GetBytes(aes.BlockSize / 8); CryptoStream cs = new CryptoStream(ms, aes.CreateDecryptor(), CryptoStreamMode.Write); cs.Write(input, 0, input.Length); cs.Close(); return ms.ToArray(); }
public static string Encrypt(string input) { return Convert.ToBase64String(Encrypt(Encoding.UTF8.GetBytes(input))); } public static string Decrypt(string input) { return Encoding.UTF8.GetString(Decrypt(Convert.FromBase64String(input))); }
using System.Text; using System.IO; using System.Security.Cryptography;
Thanks for reading! And if you want to get in touch, I'd love to hear from you: chris.hulbert at gmail.
(Comp Sci, Hons - UTS)
Software Developer (Freelancer / Contractor) in Australia.
I have worked at places such as Google, Cochlear, Assembly Payments, News Corp, Fox Sports, NineMSN, FetchTV, Coles, Woolworths, Trust Bank, and Westpac, among others. If you're looking for help developing an iOS app, drop me a line!
Get in touch:
[email protected]
github.com/chrishulbert
linkedin