1195 {
1199 try
1200 {
1202 {
1204 throw hRForLastWin32Error.ToCryptographicException();
1205 }
1206 if (!global::Interop.Advapi32.CryptHashData(phHash, password, cbPassword, 0))
1207 {
1209 throw hRForLastWin32Error2.ToCryptographicException();
1210 }
1211 if (!
CryptDeriveKey(hProv, algid, phHash, dwFlags | 1, out phKey))
1212 {
1214 throw hRForLastWin32Error3.ToCryptographicException();
1215 }
1216 byte[] key_out = null;
1217 int cb_out = 0;
1218 UnloadKey(hProv, phKey, ref key_out, ref cb_out);
1219 int pdwDataLen = 0;
1220 if (!global::Interop.Advapi32.CryptGetKeyParam(phKey, global::Interop.Advapi32.CryptGetKeyParamFlags.KP_IV, null, ref pdwDataLen, 0))
1221 {
1223 throw hRForLastWin32Error4.ToCryptographicException();
1224 }
1225 byte[]
array =
new byte[pdwDataLen];
1226 if (!global::Interop.Advapi32.CryptGetKeyParam(phKey, global::Interop.Advapi32.CryptGetKeyParamFlags.KP_IV,
array, ref pdwDataLen, 0))
1227 {
1229 throw hRForLastWin32Error5.ToCryptographicException();
1230 }
1231 if (pdwDataLen != cbIV_In)
1232 {
1234 }
1236 pbKey = new byte[cb_out];
1238 }
1239 finally
1240 {
1241 phKey?.Dispose();
1242 phHash?.Dispose();
1243 }
1244 }
static bool CryptCreateHash(SafeProvHandle hProv, int algId, SafeKeyHandle hKey, global::Interop.Advapi32.CryptCreateHashFlags dwFlags, out SafeHashHandle phHash)
static void UnloadKey(SafeProvHandle hProv, SafeKeyHandle hKey, [NotNull] ref byte[] key_out, ref int cb_out)
static void VerifyValidHandle(SafeHandleZeroOrMinusOneIsInvalid handle)
static bool CryptDeriveKey(SafeProvHandle hProv, int algId, SafeHashHandle phHash, int dwFlags, out SafeKeyHandle phKey)
static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count)
static int GetHRForLastWin32Error()
static string Cryptography_PasswordDerivedBytes_InvalidIV
static SafeKeyHandle InvalidHandle