示例#1
0
 /// <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>
        /// <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();
		}
 private void Dispose()
 {
     if (!m_Disposed) {
         m_Disposed = true;
         if (m_Managed != null) {
             m_Managed.Clear();
             m_Managed = null;
         }
         GC.SuppressFinalize(this);
     }
 }