public static byte[] EncryptData(string password, AutoSaltSizes saltSize, byte[] data, SymmetricCryptoAlgorithm algorithm = SymmetricCryptoAlgorithm.AES_256_CBC) { EncryptionBuffer encBuffer = new EncryptionBuffer(password, saltSize, algorithm); encBuffer.AddData(data, true); return(encBuffer.GetData()); }
public static void EncryptStream(string password, AutoSaltSizes saltSize, Stream inputStream, Stream outputStream, SymmetricCryptoAlgorithm algorithm = SymmetricCryptoAlgorithm.AES_256_CBC) { if (!inputStream.CanRead) { throw new Exception("The input stream has to support read"); } if (!outputStream.CanWrite) { throw new Exception("The output stream has to support write"); } EncryptionBuffer encBuffer = new EncryptionBuffer(password, saltSize, algorithm); byte[] readBuffer = new byte[500000]; bool isLastData = false; while (!isLastData) { int nrOfBytes = inputStream.Read(readBuffer, 0, readBuffer.Length); isLastData = (nrOfBytes == 0); encBuffer.AddData(readBuffer, 0, nrOfBytes, isLastData); byte[] encryptedData = encBuffer.GetData(); outputStream.Write(encryptedData, 0, encryptedData.Length); } }
public String Encrypt(String value) { String pass = Password; EncryptionBuffer encBuffer = new EncryptionBuffer(pass, Salt, SymmetricCryptoAlgorithm.AES_192_CBC); encBuffer.AddData(Encoding.Unicode.GetBytes(value), true); return(Convert.ToBase64String(encBuffer.GetData())); }