public Encryptor(EncryptionSettings settings) { var symmetricKey = CreateSymmetricKey(); var keyBytes = GetKeyBytes(settings); var initVectorBytes = Encoding.ASCII.GetBytes(settings.InitVector); encryptor = symmetricKey.CreateEncryptor(keyBytes, initVectorBytes); decryptor = symmetricKey.CreateDecryptor(keyBytes, initVectorBytes); }
static byte[] GetKeyBytes(EncryptionSettings settings) { var saltBytes = Encoding.ASCII.GetBytes(settings.SaltValue); var password = new Rfc2898DeriveBytes(settings.PassPhrase, saltBytes, settings.PasswordIterations); var keyBytes = password.GetBytes(settings.KeySize/8); return keyBytes; }