/// <summary> /// Initializes a new instance of the <see cref="RC4CryptoServiceProvider"/> class. /// </summary> /// <exception cref="CryptographicException">An error occurs while acquiring the CSP.</exception> public RC4CryptoServiceProvider() { // acquire an RC4 context m_Provider = CryptoHandle.Handle; if (m_Provider != IntPtr.Zero) { int dwFlags = NativeMethods.CRYPT_FIRST; bool found = false; IntPtr provEnum = Marshal.AllocHGlobal(100); int dwSize; do { dwSize = 100; if (NativeMethods.CryptGetProvParam(m_Provider, NativeMethods.PP_ENUMALGS_EX, provEnum, ref dwSize, dwFlags) == 0) { break; } dwFlags = 0; PROV_ENUMALGS_EX eax = (PROV_ENUMALGS_EX)Marshal.PtrToStructure(provEnum, typeof(PROV_ENUMALGS_EX)); if (eax.aiAlgid == NativeMethods.CALG_RC4) { found = true; m_MinLen = eax.dwMinLen; m_MaxLen = eax.dwMaxLen; } } while (!found); Marshal.FreeHGlobal(provEnum); } m_Managed = new ARCFourManaged(); }
/// <summary> /// Initializes a new instance of the <see cref="RC4CryptoServiceProvider"/> class. /// </summary> public RC4CryptoServiceProvider() { // acquire an RC4 context m_Provider = CAPIProvider.Handle; /* if (SspiProvider.CryptAcquireContext(ref m_Provider, IntPtr.Zero, null, SecurityConstants.PROV_RSA_FULL, 0) == 0) { * if (Marshal.GetLastWin32Error() == SecurityConstants.NTE_BAD_KEYSET) * SspiProvider.CryptAcquireContext(ref m_Provider, IntPtr.Zero, null, SecurityConstants.PROV_RSA_FULL, SecurityConstants.CRYPT_NEWKEYSET); * }*/ if (m_Provider != 0) { int dwFlags = SecurityConstants.CRYPT_FIRST; bool found = false; IntPtr provEnum = Marshal.AllocHGlobal(100); int dwSize; do { dwSize = 100; if (SspiProvider.CryptGetProvParam(m_Provider, SecurityConstants.PP_ENUMALGS_EX, provEnum, ref dwSize, dwFlags) == 0) { break; } dwFlags = 0; PROV_ENUMALGS_EX eax = (PROV_ENUMALGS_EX)Marshal.PtrToStructure(provEnum, typeof(PROV_ENUMALGS_EX)); if (eax.aiAlgid == SecurityConstants.CALG_RC4) { found = true; m_MinLen = eax.dwMinLen; m_MaxLen = eax.dwMaxLen; } } while (!found); Marshal.FreeHGlobal(provEnum); /* if (!found) { * SspiProvider.CryptReleaseContext(m_Provider, 0); * m_Provider = 0; * }*/ } m_Managed = new ARCFourManaged(); }