C# has AES encryption built in.
but before using it you need to go through Decrypt string in C# that was encrypted with PHP openssl_encrypt - since
PHP doesn't even use a key derivation algorithm just takes the bytes of the passphrase and pads it out with zero's
Once you got your iv and key you can use AesManaged and CrytproStream to encrypt the data:
byte[] iv = null; // get iv form pw
byte[] key = null; // get key from pw
using (AesManaged cryptor = new AesManaged())
{
ivhex = BitConverter.ToString(iv).Replace("-", string.Empty);
keyhex = BitConverter.ToString(key).Replace("-", string.Empty);
// Encrypt File
using (var ms = new MemoryStream())
{
cryptor.Mode = CipherMode.CBC;
cryptor.Padding = PaddingMode.PKCS7;
cryptor.KeySize = 256;
cryptor.BlockSize = 256;
//We use the random generated iv created by AesManaged
using (CryptoStream cs = new CryptoStream((Stream)ms, cryptor.CreateEncryptor(key, iv), CryptoStreamMode.Write))
{
using (StreamWriter swEncrypt = new StreamWriter(cs))
{
swEncrypt.Write(text);
}
}
return Convert.ToBase64String(ms.ToArray());
}
}