internal void ProcessEncryption(crypto.Aes cipher, CommandLine commandLine) { var key = new Rfc2898DeriveBytes(commandLine.Password, commandLine.KeySaltLength, commandLine.KeyIterations); cipher.GenerateIV(); cipher.Key = key.GetBytes(cipher.KeySize / 8); Stream inputStream = CreateInputStream(commandLine); Stream outputStream = CreateOutputStream(commandLine); // 2 bytes of version outputStream.Write(Constants.FormatVersionBytes, 0, Constants.FormatVersionBytes.Length); // stores 16 bytes of IV outputStream.Write(cipher.IV, 0, cipher.IV.Length); // stores 2 bytes of salt size (in network order) short saltLength = IPAddress.HostToNetworkOrder((short)key.Salt.Length); byte[] saltLengthBytes = BitConverter.GetBytes(saltLength); outputStream.Write(saltLengthBytes, 0, saltLengthBytes.Length); // stores n bytes of salt outputStream.Write(key.Salt, 0, key.Salt.Length); using (ICryptoTransform encryptor = cipher.CreateEncryptor()) { using (Stream cryptoStream = new CryptoStream(outputStream, encryptor, CryptoStreamMode.Write)) inputStream.CopyTo(cryptoStream); } }
public AES(byte[] key) { rsa = new AesManaged(); rsa.GenerateKey(); rsa.GenerateIV(); _decoder = rsa.CreateDecryptor(); _encoder = rsa.CreateEncryptor(); }
public AesCrypt() { aes = Aes.Create(); aes.Mode = CipherMode.CBC; aes.GenerateIV(); aes.GenerateKey(); aes.Padding = PaddingMode.PKCS7; }
public AesExtensionsTest() { aes = System.Security.Cryptography.Aes.Create(); aes.Mode = CipherMode.ECB; aes.Padding = PaddingMode.PKCS7; aes.BlockSize = 128; aes.GenerateKey(8); aes.GenerateIV(8); }
public SimpleAes(byte[] key) { aes = Aes.Create(); aes.GenerateIV(); aes.Key = key; encryptor = aes.CreateEncryptor(key, aes.IV); decryptor = aes.CreateDecryptor(key, aes.IV); }
public override void GenerateIV() => _impl.GenerateIV();
private void SetResponseVerifier(Response r, Aes aes) { aes.GenerateIV(); r.Nonce = encode64(aes.IV); r.Verifier = CryptoTransform(r.Nonce, false, true, aes, CMode.ENCRYPT); }
public static void WriteMessageStream(MemoryStream outStream, Message outMessage, string sessionKey, Aes aes, bool encrypt) { outMessage.ReplaceControlValue(Message.TimestampControlValueName, DateTime.Now.ToUniversalTime().ToString()); outMessage.ReplaceControlValue(Message.SessionKeyControlValueName, sessionKey); if (encrypt) { aes.GenerateIV(); StreamUtilities.WriteStringToMemoryStream(outStream, aes.IV.Length + "!"); outStream.Write(aes.IV, 0, aes.IV.Length); StreamUtilities.RunCryptoTransform(outMessage.Serialize(), aes.CreateEncryptor(), outStream, true); } else { outMessage.Serialize(outStream); } }
public static bool TestGenerate(Aes aes) { byte[] key = aes.Key; byte[] IV = aes.IV; aes.GenerateKey(); aes.GenerateIV(); if (aes.Key.Length != 32) { Console.WriteLine("Error - Aes.GenerateKey wrong length: {0}", aes.Key.Length); return false; } if (aes.IV.Length != 16) { Console.WriteLine("Error - Aes.GenerateIV wrong length: {0}", aes.IV.Length); return false; } if (CompareBytes(aes.Key, key)) { Console.WriteLine("Error - Aes.GenerateKey did not change key"); return false; } if (CompareBytes(aes.IV, IV)) { Console.WriteLine("Error - Aes.GenerateIV did not change IV"); return false; } return true; }