@@ -10,8 +10,15 @@ namespace Microsoft.EntityFrameworkCore.DataEncryption.Providers
1010 /// </summary>
1111 public class AesProvider : IEncryptionProvider
1212 {
13- private const int AesBlockSize = 128 ;
14- private const int InitializationVectorSize = 16 ;
13+ /// <summary>
14+ /// AES block size constant.
15+ /// </summary>
16+ public const int AesBlockSize = 128 ;
17+
18+ /// <summary>
19+ /// Initialization vector size constant.
20+ /// </summary>
21+ public const int InitializationVectorSize = 16 ;
1522
1623 private readonly byte [ ] _key ;
1724 private readonly CipherMode _mode ;
@@ -59,20 +66,16 @@ public string Encrypt(string dataToEncrypt)
5966
6067 byte [ ] initializationVector = cryptoServiceProvider . IV ;
6168
62- using ( ICryptoTransform encryptor = cryptoServiceProvider . CreateEncryptor ( _key , initializationVector ) )
69+ using ICryptoTransform encryptor = cryptoServiceProvider . CreateEncryptor ( _key , initializationVector ) ;
70+ using var memoryStream = new MemoryStream ( ) ;
71+ using ( var cryptoStream = new CryptoStream ( memoryStream , encryptor , CryptoStreamMode . Write ) )
6372 {
64- using ( var memoryStream = new MemoryStream ( ) )
65- {
66- using ( var cryptoStream = new CryptoStream ( memoryStream , encryptor , CryptoStreamMode . Write ) )
67- {
68- memoryStream . Write ( initializationVector , 0 , initializationVector . Length ) ;
69- cryptoStream . Write ( input , 0 , input . Length ) ;
70- cryptoStream . FlushFinalBlock ( ) ;
71- }
72-
73- encrypted = memoryStream . ToArray ( ) ;
74- }
73+ memoryStream . Write ( initializationVector , 0 , initializationVector . Length ) ;
74+ cryptoStream . Write ( input , 0 , input . Length ) ;
75+ cryptoStream . FlushFinalBlock ( ) ;
7576 }
77+
78+ encrypted = memoryStream . ToArray ( ) ;
7679 }
7780
7881 return Convert . ToBase64String ( encrypted ) ;
0 commit comments