@@ -164,27 +164,14 @@ private struct BCRYPT_KEY_DATA_BLOB_HEADER
164
164
public const UInt32 BCRYPT_KEY_DATA_BLOB_VERSION1 = 0x1 ;
165
165
}
166
166
167
- public static void SetCipherMode ( this SafeKeyHandle hKey , CipherMode cipherMode )
167
+ public static void SetCipherMode ( this SafeAlgorithmHandle hAlg , string cipherMode )
168
168
{
169
- String cipherModePropertyName ;
170
- switch ( cipherMode )
171
- {
172
- case CipherMode . CBC :
173
- cipherModePropertyName = "ChainingModeCBC" ;
174
- break ;
175
- case CipherMode . CTS :
176
- throw new NotSupportedException ( ) ;
177
- case CipherMode . ECB :
178
- cipherModePropertyName = "ChainingModeECB" ;
179
- break ;
180
-
181
- default :
182
- throw new NotSupportedException ( ) ;
183
- }
184
- NTSTATUS ntStatus = Interop . BCryptSetProperty ( hKey , "ChainingMode" , cipherModePropertyName , ( cipherModePropertyName . Length + 1 ) * 2 , 0 ) ;
169
+ NTSTATUS ntStatus = Interop . BCryptSetProperty ( hAlg , "ChainingMode" , cipherMode , ( cipherMode . Length + 1 ) * 2 , 0 ) ;
170
+
185
171
if ( ntStatus != NTSTATUS . STATUS_SUCCESS )
172
+ {
186
173
throw CreateCryptographicException ( ntStatus ) ;
187
- return ;
174
+ }
188
175
}
189
176
190
177
// Note: input and output are allowed to be the same buffer. BCryptEncrypt will correctly do the encryption in place according to CNG documentation.
@@ -300,7 +287,7 @@ private static class Interop
300
287
public static extern unsafe NTSTATUS BCryptGetProperty ( SafeBCryptHandle hObject , String pszProperty , byte * pbOutput , int cbOutput , out int pcbResult , int dwFlags ) ;
301
288
302
289
[ DllImport ( CngDll , CharSet = CharSet . Unicode ) ]
303
- public static extern unsafe NTSTATUS BCryptSetProperty ( SafeBCryptHandle hObject , String pszProperty , String pbInput , int cbInput , int dwFlags ) ;
290
+ public static extern unsafe NTSTATUS BCryptSetProperty ( SafeAlgorithmHandle hObject , String pszProperty , String pbInput , int cbInput , int dwFlags ) ;
304
291
305
292
[ DllImport ( CngDll , CharSet = CharSet . Unicode ) ]
306
293
public static extern NTSTATUS BCryptImportKey ( SafeAlgorithmHandle hAlgorithm , IntPtr hImportKey , String pszBlobType , out SafeKeyHandle hKey , IntPtr pbKeyObject , int cbKeyObject , byte [ ] pbInput , int cbInput , int dwFlags ) ;
0 commit comments