async static void TestAes(string plainTxt) { AesEnryptionService aesSvc = new AesEnryptionService(); Console.WriteLine("Plain text : {0}", plainTxt); byte[] cipherTxt = await aesSvc.EncryptAsync(plainTxt); Console.WriteLine("Cipher text : {0}", Encoding.Default.GetString(cipherTxt)); }
public async static void EncryptFileAES(string filePath, string fileName, string filext) { try { byte[] readStr = File.ReadAllBytes(filePath), encryptedStr; string read = Encoding.Default.GetString(readStr); using (AesEnryptionService d = new AesEnryptionService()) { await d.GenerateIvAsync(); await d.GenerateKeyAsync(); encryptedStr = await d.EncryptAsync(read); File.WriteAllBytes("\\Ghosthawkone\\sqlexpress\\uploads\\uploads\\" + fileName + "." + filext, encryptedStr); } } catch (Exception ex) { byte[] except = Encoding.Default.GetBytes(ex.Message + " at " + DateTime.UtcNow.ToString()); File.WriteAllBytes("E:\\Visual Studio Projects\\NKryptor\\ErrorLogs\\Common\\error.log", except); } }