@@ -26,7 +26,7 @@ public class SqlColumnEncryptionCspProvider : SqlColumnEncryptionKeyStoreProvide
26
26
internal const string MasterKeyType = @"asymmetric key" ;
27
27
28
28
/// <summary>
29
- /// This encryption keystore uses the master key path to reference a CSP.
29
+ /// This encryption keystore uses the master key path to reference a CSP provider .
30
30
/// </summary>
31
31
internal const string KeyPathReference = @"Microsoft Cryptographic Service Provider (CSP)" ;
32
32
@@ -102,10 +102,10 @@ public override bool VerifyColumnMasterKeyMetadata(string? masterKeyPath, bool a
102
102
103
103
/// <summary>
104
104
/// This function validates that the encryption algorithm is RSA_OAEP and if it is not,
105
- /// then throws an exception
105
+ /// then throws an exception.
106
106
/// </summary>
107
- /// <param name="encryptionAlgorithm">Asymmetric key encryption algorithm</param>
108
- /// <param name="isSystemOp">Indicates if ADO.NET calls or the customer calls the API</param>
107
+ /// <param name="encryptionAlgorithm">Asymmetric key encryption algorithm. </param>
108
+ /// <param name="isSystemOp">Indicates if ADO.NET calls or the customer calls the API. </param>
109
109
private static void ValidateEncryptionAlgorithm ( [ NotNull ] string ? encryptionAlgorithm , bool isSystemOp )
110
110
{
111
111
// This validates that the encryption algorithm is RSA_OAEP
@@ -123,8 +123,8 @@ private static void ValidateEncryptionAlgorithm([NotNull] string? encryptionAlgo
123
123
/// <summary>
124
124
/// Checks if the CSP key path is Empty or Null (and raises exception if they are).
125
125
/// </summary>
126
- /// <param name="masterKeyPath">CSP key path .</param>
127
- /// <param name="isSystemOp">Indicates if ADO.NET calls or the customer calls the API</param>
126
+ /// <param name="masterKeyPath">Key path containing the CSP provider name and key name .</param>
127
+ /// <param name="isSystemOp">Indicates if ADO.NET calls or the customer calls the API. </param>
128
128
private static void ValidateNonEmptyCSPKeyPath ( [ NotNull ] string ? masterKeyPath , bool isSystemOp )
129
129
{
130
130
if ( masterKeyPath is null )
@@ -139,10 +139,10 @@ private static void ValidateNonEmptyCSPKeyPath([NotNull] string? masterKeyPath,
139
139
}
140
140
141
141
/// <summary>
142
- /// Creates a RSACryptoServiceProvider from the given key path which contains both CSP name and key name
142
+ /// Creates a RSACryptoServiceProvider from the given key path.
143
143
/// </summary>
144
- /// <param name="keyPath">key path in the format of [CAPI provider name]/[key name]</param>
145
- /// <param name="isSystemOp">Indicates if ADO.NET calls or the customer calls the API</param>
144
+ /// <param name="keyPath">Key path in the format of [CSP provider name]/[key name]. </param>
145
+ /// <param name="isSystemOp">Indicates if ADO.NET calls or the customer calls the API. </param>
146
146
/// <returns></returns>
147
147
private static RSACryptoServiceProvider CreateRSACryptoProvider ( string keyPath , bool isSystemOp )
148
148
{
@@ -154,35 +154,27 @@ private static RSACryptoServiceProvider CreateRSACryptoProvider(string keyPath,
154
154
155
155
// Create a new instance of CspParameters for an RSA container.
156
156
CspParameters cspParams = new ( providerType , cspProviderName , keyName ) { Flags = CspProviderFlags . UseExistingKey } ;
157
+ const int KEYSETDOESNOTEXIST = - 2146893802 ;
157
158
158
159
try
159
160
{
160
161
// Create a new instance of RSACryptoServiceProvider
161
162
return new RSACryptoServiceProvider ( cspParams ) ;
162
163
}
163
- catch ( CryptographicException e )
164
+ catch ( CryptographicException e ) when ( e . HResult == KEYSETDOESNOTEXIST )
164
165
{
165
- const int KEYSETDOESNOTEXIST = - 2146893802 ;
166
- if ( e . HResult == KEYSETDOESNOTEXIST )
167
- {
168
- // Key does not exist
169
- throw SQL . InvalidCspKeyIdentifier ( keyName , keyPath , isSystemOp ) ;
170
- }
171
- else
172
- {
173
- // Bubble up the exception
174
- throw ;
175
- }
166
+ // Key does not exist
167
+ throw SQL . InvalidCspKeyIdentifier ( keyName , keyPath , isSystemOp ) ;
176
168
}
177
169
}
178
170
179
171
/// <summary>
180
- /// Extracts the CSP provider name and key name from the given key path
172
+ /// Extracts the CSP provider name and key name from the given key path.
181
173
/// </summary>
182
- /// <param name="keyPath">key path in the format of [CSP provider name]/[key name]</param>
183
- /// <param name="isSystemOp">Indicates if ADO.NET calls or the customer calls the API</param>
184
- /// <param name="cspProviderName">output containing the CSP provider name</param>
185
- /// <param name="keyIdentifier">output containing the key name </param>
174
+ /// <param name="keyPath">Key path in the format [CSP provider name]/[key name]. </param>
175
+ /// <param name="isSystemOp">Indicates if ADO.NET calls or the customer calls the API. </param>
176
+ /// <param name="cspProviderName">CSP provider name. </param>
177
+ /// <param name="keyIdentifier">Key name inside the CSP provider. </param>
186
178
private static void GetCspProviderAndKeyName ( string keyPath , bool isSystemOp , out string cspProviderName , out string keyIdentifier )
187
179
{
188
180
int indexOfSlash = keyPath . IndexOf ( '/' ) ;
@@ -205,11 +197,11 @@ private static void GetCspProviderAndKeyName(string keyPath, bool isSystemOp, ou
205
197
}
206
198
207
199
/// <summary>
208
- /// Gets the provider type from a given CAPI provider name
200
+ /// Gets the type from a given CSP provider name.
209
201
/// </summary>
210
- /// <param name="providerName">CAPI provider name</param>
211
- /// <param name="keyPath">key path in the format of [CSP provider name]/[key name]</param>
212
- /// <param name="isSystemOp">Indicates if ADO.NET calls or the customer calls the API</param>
202
+ /// <param name="providerName">CSP provider name. </param>
203
+ /// <param name="keyPath">Key path in the format of [CSP provider name]/[key name]. </param>
204
+ /// <param name="isSystemOp">Indicates if ADO.NET calls or the customer calls the API. </param>
213
205
/// <returns></returns>
214
206
private static int GetProviderType ( string providerName , string keyPath , bool isSystemOp )
215
207
{
0 commit comments