⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 crypto.cs

📁 蓝牙通讯
💻 CS
📖 第 1 页 / 共 4 页
字号:
		private static extern bool CryptDestroyHashCe(IntPtr hHash); 
		[DllImport(advapi32, EntryPoint="CryptDestroyHash", SetLastError=true)] 
		private static extern bool CryptDestroyHashXp(IntPtr hHash); 
		
		///<summary>
		///This function releases the handle referenced by the hKey parameter. Once a key 
		///handle has been released, it becomes invalid and cannot be used again.
		///If the handle refers to a session key, or to a public key that has been imported 
		///into the cryptographic service provider (CSP) through CryptImportKey, the 
		///CryptDestroyKey function destroys the key and frees the memory that the key 
		///occupied. Many CSPs scrub the memory where the key was held before freeing it.																																																																															  
		///On the other hand, if the handle refers to a public/private key pair obtained from 
		///the CryptGetUserKey function, the underlying key pair is not destroyed by the 
		///CryptDestroyKey function. Only the handle is destroyed.
		///</summary>
		/// <remarks>
		/// raCrypto / works on smartPhone
		/// </remarks>
		public static bool CryptDestroyKey(IntPtr hKey)
		{
			if(System.Environment.OSVersion.Platform == PlatformID.WinCE)
				return CryptDestroyKeyCe(hKey);
			else
				return CryptDestroyKeyXp(hKey);
		}
		//6    5 000076A8 CPDestroyKey 
		//BOOL CRYPTFUNC CryptDestroyKey(HCRYPTKEY hKey);
		[DllImport(coredll, EntryPoint="CryptDestroyKey", SetLastError=true)] 
		private static extern bool CryptDestroyKeyCe(IntPtr hKey);
		[DllImport(advapi32, EntryPoint="CryptDestroyKey", SetLastError=true)] 
		private static extern bool CryptDestroyKeyXp(IntPtr hKey);
		
		///<summary>
		///This function makes an exact copy of a hash and the state the hash is in.
		///A hash can be created in a piece-by-piece way. This function can create separate 
		///hashes of two different contents that begin with the same content. 
		///</summary>
		/// <remarks>
		/// did not work on smartPhone, dont need it
		/// </remarks>
		public static bool CryptDuplicateHash(IntPtr hHash, ref uint pdwReserved, uint dwFlags, out IntPtr phHash)
		{
			if(System.Environment.OSVersion.Platform == PlatformID.WinCE)
				return CryptDuplicateHashCe(hHash, ref pdwReserved, dwFlags, out phHash);
			else
				return CryptDuplicateHashXp(hHash, ref pdwReserved, dwFlags, out phHash);
		}
		//7    6 00005C00 CPDuplicateHash 
		//BOOL WINAPI CryptDuplicateHash(HCRYPTHASH hHash, DWORD* pdwReserved, DWORD dwFlags, HCRYPTHASH* phHash);
		[DllImport(coredll, EntryPoint="CryptDuplicateHash", SetLastError=true)] 
		private static extern bool CryptDuplicateHashCe(IntPtr hHash, ref uint pdwReserved, uint dwFlags, out IntPtr phHash);
		[DllImport(advapi32, EntryPoint="CryptDuplicateHash", SetLastError=true)] 
		private static extern bool CryptDuplicateHashXp(IntPtr hHash, ref uint pdwReserved, uint dwFlags, out IntPtr phHash);
		
		///<summary>
		///This function makes an exact copy of a key and the state the key is in. 
		///Some keys have an associated state, for example, an initialization vector and/or 
		///a salt value.
		///</summary>
		/// <remarks>
		/// did not work on smartPhone, dont need it
		/// </remarks>
		public static bool CryptDuplicateKey(IntPtr hKey, ref uint pdwReserved, uint dwFlags, out IntPtr phKey)
		{
			if(System.Environment.OSVersion.Platform == PlatformID.WinCE)
				return CryptDuplicateKeyCe(hKey, ref pdwReserved, dwFlags, out phKey);
			else
				return CryptDuplicateKeyXp(hKey, ref pdwReserved, dwFlags, out phKey);
		}
		//8    7 000091C8 CPDuplicateKey 
		//BOOL WINAPI CryptDuplicateKey(HCRYPTKEY hKey, DWORD* pdwReserved, DWORD dwFlags, HCRYPTKEY* phKey);
		[DllImport(coredll, EntryPoint="CryptDuplicateKey", SetLastError=true)] 
		private static extern bool CryptDuplicateKeyCe(IntPtr hKey, ref uint pdwReserved, uint dwFlags, out IntPtr phKey);
		[DllImport(advapi32, EntryPoint="CryptDuplicateKey", SetLastError=true)] 
		private static extern bool CryptDuplicateKeyXp(IntPtr hKey, ref uint pdwReserved, uint dwFlags, out IntPtr phKey);
		
		///<summary>
		///This function encrypts data. The key held by the cryptographic service provider 
		///(CSP) module and referenced by the hKey parameter specifies the algorithm used to 
		///encrypt the data parameter.
		///</summary>
		/// <remarks>
		/// raCrypto, mca / works on smartPhone
		/// </remarks>
		public static bool CryptEncrypt(IntPtr hKey, IntPtr hHash, bool Final, uint dwFlags, byte[] pbData, ref uint pdwDataLen, uint dwBufLen)
		{
			if(System.Environment.OSVersion.Platform == PlatformID.WinCE)
				return CryptEncryptCe(hKey, hHash, Final, dwFlags, pbData, ref pdwDataLen, dwBufLen);
			else
				return CryptEncryptXp(hKey, hHash, Final, dwFlags, pbData, ref pdwDataLen, dwBufLen);
		}
		//9    8 00004838 CPEncrypt 
		//BOOL CRYPTFUNC CryptEncrypt(HCRYPTKEY hKey, HCRYPTHASH hHash, BOOL Final, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen, DWORD dwBufLen);
		[DllImport(coredll, EntryPoint="CryptEncrypt", SetLastError=true)]
		private static extern bool CryptEncryptCe(IntPtr hKey, IntPtr hHash, bool Final, uint dwFlags, byte[] pbData, ref uint pdwDataLen, uint dwBufLen);
		[DllImport(advapi32, EntryPoint="CryptEncrypt", SetLastError=true)]
		private static extern bool CryptEncryptXp(IntPtr hKey, IntPtr hHash, bool Final, uint dwFlags, byte[] pbData, ref uint pdwDataLen, uint dwBufLen);
		
		///<summary>
		///This function retrieves the first or next available cryptographic service provider 
		///(CSP). Used in a loop, this function can retrieve in sequence all of the CSPs 
		///available on a computer.
		///</summary>
		/// <remarks>
		/// works on smartPhone
		/// </remarks>
		public static bool CryptEnumProviders(uint dwIndex, ref uint pdwReserved, uint dwFlags, ref uint pdwProvType, StringBuilder pszProvName, ref uint pcbProvName)
		{
			if(System.Environment.OSVersion.Platform == PlatformID.WinCE)
				return CryptEnumProvidersCe(dwIndex, ref pdwReserved, dwFlags, ref pdwProvType, pszProvName, ref pcbProvName);
			else
				return CryptEnumProvidersXp(dwIndex, ref pdwReserved, dwFlags, ref pdwProvType, pszProvName, ref pcbProvName);
		}
		//BOOL WINAPI CryptEnumProviders(DWORD dwIndex, DWORD* pdwReserved, DWORD dwFlags, DWORD* pdwProvType, LPTSTR pszProvName, DWORD* pcbProvName);
		[DllImport(coredll, EntryPoint="CryptEnumProviders", SetLastError=true)]
		private static extern bool CryptEnumProvidersCe(uint dwIndex, ref uint pdwReserved, uint dwFlags, ref uint pdwProvType, StringBuilder pszProvName, ref uint pcbProvName);
		[DllImport(advapi32, EntryPoint="CryptEnumProviders", SetLastError=true)]
		private static extern bool CryptEnumProvidersXp(uint dwIndex, ref uint pdwReserved, uint dwFlags, ref uint pdwProvType, StringBuilder pszProvName, ref uint pcbProvName);
		
		///<summary>
		///This function retrieves the first or next type of cryptographic service provider 
		///(CSP) supported on the computer. Used in a loop, this function retrieves in 
		///sequence all of the CSP types available on a computer.
		///</summary>
		/// <remarks>
		/// did not work on smartPhone
		/// used return values from CryptEnumProviders instead
		/// </remarks>
		public static bool CryptEnumProviderTypes(uint dwIndex, ref uint pdwReserved, uint dwFlags, ref uint pdwProvType, StringBuilder pszTypeName, ref uint pcbTypeName)
		{
			if(System.Environment.OSVersion.Platform == PlatformID.WinCE)
				return CryptEnumProviderTypesCe(dwIndex, ref pdwReserved, dwFlags, ref pdwProvType, pszTypeName, ref pcbTypeName);
			else
				return CryptEnumProviderTypesXp(dwIndex, ref pdwReserved, dwFlags, ref pdwProvType, pszTypeName, ref pcbTypeName);
		}
		//BOOL WINAPI CryptEnumProviderTypes(DWORD dwIndex, DWORD* pdwReserved, DWORD dwFlags, DWORD* pdwProvType, LPTSTR pszTypeName, DWORD* pcbTypeName);
		[DllImport(coredll, EntryPoint="CryptEnumProviderTypes", SetLastError=true)]
		private static extern bool CryptEnumProviderTypesCe(uint dwIndex, ref uint pdwReserved, uint dwFlags, ref uint pdwProvType, StringBuilder pszTypeName, ref uint pcbTypeName);
		[DllImport(advapi32, EntryPoint="CryptEnumProviderTypes", SetLastError=true)]
		private static extern bool CryptEnumProviderTypesXp(uint dwIndex, ref uint pdwReserved, uint dwFlags, ref uint pdwProvType, StringBuilder pszTypeName, ref uint pcbTypeName);

		///<summary>
		///This function exports cryptographic keys from of a cryptographic service provider 
		///(CSP) in a secure manner.
		///The caller passes to the CryptImportKey function a handle to the key to be exported 
		///and gets a key binary large object (BLOB). This key BLOB can be sent over a 
		///nonsecure transport or stored in a nonsecure storage location. The key BLOB is 
		///useless until the intended recipient uses the CryptImportKey function, which 
		///imports the key into the recipient's CSP.
		///</summary>
		/// <remarks>
		/// mca / works on smartPhone
		/// </remarks>
		public static bool CryptExportKey(IntPtr hKey, IntPtr hExpKey, uint dwBlobType, uint dwFlags, byte[] pbData, ref uint pdwDataLen)
		{
			if(System.Environment.OSVersion.Platform == PlatformID.WinCE)
				return CryptExportKeyCe(hKey, hExpKey, dwBlobType, dwFlags, pbData, ref pdwDataLen);
			else
				return CryptExportKeyXp(hKey, hExpKey, dwBlobType, dwFlags, pbData, ref pdwDataLen);
		}
		//10    9 0000692C CPExportKey 
		//BOOL WINAPI CryptExportKey(HCRYPTKEY hKey, HCRYPTKEY hExpKey, DWORD dwBlobType, DWORD dwFlags, BYTE* pbData, DWORD* pdwDataLen);
		[DllImport(coredll, EntryPoint="CryptExportKey", SetLastError=true)]
		private static extern bool CryptExportKeyCe(IntPtr hKey, IntPtr hExpKey, uint dwBlobType, uint dwFlags, byte[] pbData, ref uint pdwDataLen);
		[DllImport(advapi32, EntryPoint="CryptExportKey", SetLastError=true)]
		private static extern bool CryptExportKeyXp(IntPtr hKey, IntPtr hExpKey, uint dwBlobType, uint dwFlags, byte[] pbData, ref uint pdwDataLen);
		
		///<summary>
		///This function generates a random cryptographic session key or a public/private 
		///key pair for use with the cryptographic service provider (CSP) module. 
		///The function returns a handle to the key in the phKey parameter. 
		///This handle can then be used as needed with any of the other CryptoAPI functions 
		///requiring a key handle. 
		///When calling this function, the application must specify the algorithm. 
		///Because this algorithm type is kept bundled with the key, the application does not 
		///need to specify the algorithm later when the actual cryptographic operations are 
		///performed.
		///</summary>
		/// <remarks>
		/// mca / works on smartPhone
		/// </remarks>
		public static bool CryptGenKey(IntPtr hProv, uint Algid, uint dwFlags, out IntPtr phKey)
		{
			if(System.Environment.OSVersion.Platform == PlatformID.WinCE)
				return CryptGenKeyCe(hProv, Algid, dwFlags, out phKey);
			else
				return CryptGenKeyXp(hProv, Algid, dwFlags, out phKey);
		}
		//11    A 000062BC CPGenKey 
		//BOOL WINAPI CryptGenKey(HCRYPTPROV hProv, ALG_ID Algid, DWORD dwFlags, HCRYPTKEY* phKey);
		[DllImport(coredll, EntryPoint="CryptGenKey", SetLastError=true)]
		private static extern bool CryptGenKeyCe(IntPtr hProv, uint Algid, uint dwFlags, out IntPtr phKey);
		[DllImport(advapi32, EntryPoint="CryptGenKey", SetLastError=true)]
		private static extern bool CryptGenKeyXp(IntPtr hProv, uint Algid, uint dwFlags, out IntPtr phKey);
		
		///<summary>
		///This function fills a buffer with random bytes.
		///</summary>
		/// <remarks>
		/// raPocketGuid / worked on smartPhone
		/// </remarks>
		public static bool CryptGenRandom(IntPtr hProv, int dwLen, byte[] pbBuffer)
		{
			if(System.Environment.OSVersion.Platform == PlatformID.WinCE)
				return CryptGenRandomCe(hProv, dwLen, pbBuffer);
			else
				return CryptGenRandomXp(hProv, dwLen, pbBuffer);
		}
		//12    B 000092A8 CPGenRandom 
		//BOOL CRYPTFUNC CrptGenRandom(HCRYPTPROV hProv, DWORD dwLen, BYTE* pbBuffer);
		[DllImport(coredll, EntryPoint="CryptGenRandom", SetLastError=true)]
		private static extern bool CryptGenRandomCe(IntPtr hProv, int dwLen, byte[] pbBuffer);
		[DllImport(advapi32, EntryPoint="CryptGenRandom", SetLastError=true)]
		private static extern bool CryptGenRandomXp(IntPtr hProv, int dwLen, byte[] pbBuffer);
		

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -