@@ -27,68 +27,10 @@ private CertificateUtility()
2727 /// System.Data assembly.
2828 /// </summary>
2929 public static Assembly systemData = Assembly . GetAssembly ( typeof ( SqlConnection ) ) ;
30- public static Type sqlClientSymmetricKey = systemData . GetType ( "Microsoft.Data.SqlClient.SqlClientSymmetricKey" ) ;
31- public static ConstructorInfo sqlColumnEncryptionKeyConstructor = sqlClientSymmetricKey . GetConstructor ( BindingFlags . NonPublic | BindingFlags . Instance , null , new Type [ ] { typeof ( byte [ ] ) } , null ) ;
32- public static Type sqlAeadAes256CbcHmac256Factory = systemData . GetType ( "Microsoft.Data.SqlClient.SqlAeadAes256CbcHmac256Factory" ) ;
33- public static MethodInfo sqlAeadAes256CbcHmac256FactoryCreate = sqlAeadAes256CbcHmac256Factory . GetMethod ( "Create" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
34- public static Type sqlClientEncryptionAlgorithm = systemData . GetType ( "Microsoft.Data.SqlClient.SqlClientEncryptionAlgorithm" ) ;
35- public static MethodInfo sqlClientEncryptionAlgorithmEncryptData = sqlClientEncryptionAlgorithm . GetMethod ( "EncryptData" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
36- public static MethodInfo sqlClientEncryptionAlgorithmDecryptData = sqlClientEncryptionAlgorithm . GetMethod ( "DecryptData" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
3730 public static Type SqlSymmetricKeyCache = systemData . GetType ( "Microsoft.Data.SqlClient.SqlSymmetricKeyCache" ) ;
3831 public static MethodInfo SqlSymmetricKeyCacheGetInstance = SqlSymmetricKeyCache . GetMethod ( "GetInstance" , BindingFlags . Static | BindingFlags . NonPublic ) ;
3932 public static FieldInfo SqlSymmetricKeyCacheFieldCache = SqlSymmetricKeyCache . GetField ( "_cache" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
4033
41- /// <summary>
42- /// ECEK Corruption types (useful for testing)
43- /// </summary>
44- internal enum ECEKCorruption
45- {
46- ALGORITHM_VERSION ,
47- CEK_LENGTH ,
48- SIGNATURE ,
49- SIGNATURE_LENGTH
50- }
51-
52- /// <summary>
53- /// Encryption Type as per the test code. Different than product code's enumeration.
54- /// </summary>
55- internal enum CColumnEncryptionType
56- {
57- PlainText = 0 ,
58- Deterministic ,
59- Randomized
60- }
61-
62- /// <summary>
63- /// Encrypt Data using AED
64- /// </summary>
65- /// <param name="plainTextData"></param>
66- /// <returns></returns>
67- internal static byte [ ] EncryptDataUsingAED ( byte [ ] plainTextData , byte [ ] key , CColumnEncryptionType encryptionType )
68- {
69- Debug . Assert ( plainTextData != null ) ;
70- Debug . Assert ( key != null && key . Length > 0 ) ;
71- byte [ ] encryptedData = null ;
72-
73- Object columnEncryptionKey = sqlColumnEncryptionKeyConstructor . Invoke ( new object [ ] { key } ) ;
74- Debug . Assert ( columnEncryptionKey != null ) ;
75-
76- Object aesFactory = Activator . CreateInstance ( sqlAeadAes256CbcHmac256Factory ) ;
77- Debug . Assert ( aesFactory != null ) ;
78-
79- object [ ] parameters = new object [ ] { columnEncryptionKey , encryptionType , SQLSetupStrategy . ColumnEncryptionAlgorithmName } ;
80- Object authenticatedAES = sqlAeadAes256CbcHmac256FactoryCreate . Invoke ( aesFactory , parameters ) ;
81- Debug . Assert ( authenticatedAES != null ) ;
82-
83- parameters = new object [ ] { plainTextData } ;
84- Object finalCellBlob = sqlClientEncryptionAlgorithmEncryptData . Invoke ( authenticatedAES , parameters ) ;
85- Debug . Assert ( finalCellBlob != null ) ;
86-
87- encryptedData = ( byte [ ] ) finalCellBlob ;
88-
89- return encryptedData ;
90- }
91-
9234 /// <summary>
9335 /// Through reflection, clear the SqlClient cache
9436 /// </summary>
@@ -99,35 +41,6 @@ internal static void CleanSqlClientCache()
9941 ClearCache ( cache ) ;
10042 }
10143
102- /// <summary>
103- /// Decrypt Data using AEAD
104- /// </summary>
105- internal static byte [ ] DecryptDataUsingAED ( byte [ ] encryptedCellBlob , byte [ ] key , CColumnEncryptionType encryptionType )
106- {
107- Debug . Assert ( encryptedCellBlob != null && encryptedCellBlob . Length > 0 ) ;
108- Debug . Assert ( key != null && key . Length > 0 ) ;
109-
110- byte [ ] decryptedData = null ;
111-
112- Object columnEncryptionKey = sqlColumnEncryptionKeyConstructor . Invoke ( new object [ ] { key } ) ;
113- Debug . Assert ( columnEncryptionKey != null ) ;
114-
115- Object aesFactory = Activator . CreateInstance ( sqlAeadAes256CbcHmac256Factory ) ;
116- Debug . Assert ( aesFactory != null ) ;
117-
118- object [ ] parameters = new object [ ] { columnEncryptionKey , encryptionType , SQLSetupStrategy . ColumnEncryptionAlgorithmName } ;
119- Object authenticatedAES = sqlAeadAes256CbcHmac256FactoryCreate . Invoke ( aesFactory , parameters ) ;
120- Debug . Assert ( authenticatedAES != null ) ;
121-
122- parameters = new object [ ] { encryptedCellBlob } ;
123- Object decryptedValue = sqlClientEncryptionAlgorithmDecryptData . Invoke ( authenticatedAES , parameters ) ;
124- Debug . Assert ( decryptedValue != null ) ;
125-
126- decryptedData = ( byte [ ] ) decryptedValue ;
127-
128- return decryptedData ;
129- }
130-
13144 internal static SqlConnection GetOpenConnection ( bool fTceEnabled , SqlConnectionStringBuilder sb , bool fSuppressAttestation = false )
13245 {
13346 SqlConnection conn = new SqlConnection ( GetConnectionString ( fTceEnabled , sb , fSuppressAttestation ) ) ;
0 commit comments