예제 #1
0
        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);
        }
예제 #2
0
 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;
 }