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

📄 crypto.cs

📁 蓝牙通讯
💻 CS
📖 第 1 页 / 共 4 页
字号:
		///pairs.
		///</summary>
		/// <remarks>
		/// raCrypto / works on smartPhone
		/// </remarks>
		public static bool CryptReleaseContext(IntPtr hProv, uint dwFlags)
		{
			if(System.Environment.OSVersion.Platform == PlatformID.WinCE)
				return CryptReleaseContextCe(hProv, dwFlags);
			else
				return CryptReleaseContextXp(hProv, dwFlags);
		}
		//20   13 0000AC30 CPReleaseContext 
		//BOOL WINAPI CryptReleaseContext(HCRYPTPROV hProv, DWORD dwFlags); 
		[DllImport(coredll, EntryPoint="CryptReleaseContext", SetLastError=true)] 
		private static extern bool CryptReleaseContextCe(IntPtr hProv, uint dwFlags); 
		[DllImport(advapi32, EntryPoint="CryptReleaseContext", SetLastError=true)] 
		private static extern bool CryptReleaseContextXp(IntPtr hProv, uint dwFlags); 
		
		///<summary>
		///This function customizes the operations of a hash object. Currently, only a single 
		///parameter is defined for this function. 
		///</summary>
		/// <remarks>
		/// works on smartPhone
		/// </remarks>
		public static bool CryptSetHashParam(IntPtr hHash, uint dwParam, byte[] pbData, uint dwFlags)
		{
			if(System.Environment.OSVersion.Platform == PlatformID.WinCE)
				return CryptSetHashParamCe(hHash, dwParam, pbData, dwFlags);
			else
				return CryptSetHashParamXp(hHash, dwParam, pbData, dwFlags);
		}
		//21   14 000086E0 CPSetHashParam 
		//BOOL WINAPI CryptSetHashParam(HCRYPTHASH hHash, DWORD dwParam, BYTE* pbData, DWORD dwFlags);
		[DllImport(coredll, EntryPoint="CryptSetHashParam", SetLastError=true)] 
		private static extern bool CryptSetHashParamCe(IntPtr hHash, uint dwParam, byte[] pbData, uint dwFlags);
		[DllImport(advapi32, EntryPoint="CryptSetHashParam", SetLastError=true)] 
		private static extern bool CryptSetHashParamXp(IntPtr hHash, uint dwParam, byte[] pbData, uint dwFlags);
		
		///<summary>
		///This function customizes various aspects of a key's operations. The values set by 
		///this function are not persisted to memory and are used only within a single session. 
		///The Microsoft cryptographic service providers (CSPs) do not allow setting the 
		///values for key exchange or signature keys; however, custom providers may define 
		///parameters that can be set on these keys.
		///</summary>
		/// <remarks>
		/// worked on smartPhone
		/// </remarks>
		public static bool CryptSetKeyParam(IntPtr hKey, uint dwParam, byte[] pbData, uint dwFlags)
		{
			if(System.Environment.OSVersion.Platform == PlatformID.WinCE)
				return CryptSetKeyParamCe(hKey, dwParam, pbData, dwFlags);
			else
				return CryptSetKeyParamXp(hKey, dwParam, pbData, dwFlags);
		}
		//22   15 000078B0 CPSetKeyParam 
		//BOOL WINAPI CryptSetKeyParam(HCRYPTKEY hKey, DWORD dwParam, BYTE* pbData, DWORD dwFlags);
		[DllImport(coredll, EntryPoint="CryptSetKeyParam", SetLastError=true)] 
		private static extern bool CryptSetKeyParamCe(IntPtr hKey, uint dwParam, byte[] pbData, uint dwFlags);
		[DllImport(advapi32, EntryPoint="CryptSetKeyParam", SetLastError=true)] 
		private static extern bool CryptSetKeyParamXp(IntPtr hKey, uint dwParam, byte[] pbData, uint dwFlags);
		
		///<summary>
		///This function specifies the current user default cryptographic service provider 
		///(CSP). Typical applications do not use this function. It is intended for use solely 
		///by administrative applications. 
		///If a current user's default provider is set, that default provider is acquired by 
		///any call by that user to the CryptAcquireContext function specifying a dwProvType 
		///provider type but not a CSP name. 
		///</summary>
		/// <remarks>
		/// worked on SmartPhone
		/// </remarks>
		public static bool CryptSetProvider(string pszProvName, uint dwProvType)
		{
			if(System.Environment.OSVersion.Platform == PlatformID.WinCE)
				return CryptSetProviderCe(pszProvName, dwProvType);
			else
				return CryptSetProviderXp(pszProvName, dwProvType);
		}
		//BOOL CRYPTFUNC CryptSetProvider(LPCTSTR pszProvName, DWORD dwProvType);
		[DllImport(coredll, EntryPoint="CryptSetProvider", SetLastError=true)] 
		private static extern bool CryptSetProviderCe(string pszProvName, uint dwProvType);
		[DllImport(advapi32, EntryPoint="CryptSetProvider", SetLastError=true)] 
		private static extern bool CryptSetProviderXp(string pszProvName, uint dwProvType);

		///<summary>
		///This function specifies the default cryptographic service provider (CSP) for the 
		///current user or the local device.
		///If a current user's default provider is set, that default provider is acquired by 
		///any call by that user to the CryptAcquireContext function specifying a dwProvType 
		///provider type but not a CSP name.
		///If a local computer default is set, calls to the CryptAcquireContext function by a 
		///user not having a current user default set and not specifying a CSP result in the 
		///use of the local computer's default CSP.
		///Typical applications do not use this function. It is intended for use solely by 
		///administrative applications. 
		///</summary>
		/// <remarks>
		/// this did not work on smartPhone, dont need it
		/// </remarks>
		public static bool CryptSetProviderEx(string pszProvName, uint dwProvType, ref uint pdwReserved, uint dwFlags)
		{
			if(System.Environment.OSVersion.Platform == PlatformID.WinCE)
				return CryptSetProviderExCe(pszProvName, dwProvType, ref pdwReserved, dwFlags);
			else
				return CryptSetProviderExXp(pszProvName, dwProvType, ref pdwReserved, dwFlags);
		}
		//BOOL WINAPI CryptSetProviderEx(LPCTSTR pszProvName, DWORD dwProvType, DWORD* pdwReserved, DWORD dwFlags);
		[DllImport(coredll, EntryPoint="CryptSetProviderEx", SetLastError=true)] 
		private static extern bool CryptSetProviderExCe(string pszProvName, uint dwProvType, ref uint pdwReserved, uint dwFlags);
		[DllImport(advapi32, EntryPoint="CryptSetProviderEx", SetLastError=true)] 
		private static extern bool CryptSetProviderExXp(string pszProvName, uint dwProvType, ref uint pdwReserved, uint dwFlags);

		///<summary>
		///This function customizes the operations of a cryptographic service provider (CSP). 
		///This function is commonly used to set a security descriptor on the key container 
		///associated with a CSP to control access to the private keys in that key container.
		///</summary>
		/// <remarks>
		/// works on smartPhone
		/// </remarks>
		public static bool CryptSetProvParam(IntPtr hProv, uint dwParam, byte[] pbData, uint dwFlags)
		{
			if(System.Environment.OSVersion.Platform == PlatformID.WinCE)
				return CryptSetProvParamCe(hProv, dwParam, pbData, dwFlags);
			else
				return CryptSetProvParamXp(hProv, dwParam, pbData, dwFlags);
		}
		//23   16 00008078 CPSetProvParam 
		//BOOL CRYPTFUNC CryptoSetProvParam(HCRYPTPROV hProv, DWORD dwParam, BYTE* pbData, DWORD dwFlags);
		[DllImport(coredll, EntryPoint="CryptSetProvParam", SetLastError=true)] 
		private static extern bool CryptSetProvParamCe(IntPtr hProv, uint dwParam, byte[] pbData, uint dwFlags);
		[DllImport(advapi32, EntryPoint="CryptSetProvParam", SetLastError=true)] 
		private static extern bool CryptSetProvParamXp(IntPtr hProv, uint dwParam, byte[] pbData, uint dwFlags);
		
		///<summary>
		///This function signs data. Because all signature algorithms are asymmetric and 
		///therefore slow, the CryptoAPI does not let data be signed directly. Instead, you 
		///must first hash the data and then use the CryptSignHash function to sign the hash 
		///value.
		///</summary>
		/// <remarks>
		/// works on smartPhone
		/// </remarks>
		public static bool CryptSignHash(IntPtr hHash, uint dwKeySpec, string sDescription, uint dwFlags, byte[] pbSignature, ref uint pdwSigLen)
		{
			if(System.Environment.OSVersion.Platform == PlatformID.WinCE)
				return CryptSignHashCe(hHash, dwKeySpec, sDescription, dwFlags, pbSignature, ref pdwSigLen);
			else
				return CryptSignHashXp(hHash, dwKeySpec, sDescription, dwFlags, pbSignature, ref pdwSigLen);
		}
		//24   17 00009304 CPSignHash 
		//BOOL WINAPI CryptSignHash(HCRYPTHASH hHash, DWORD dwKeySpec, LPCTSTR sDescription, DWORD dwFlags, BYTE* pbSignature, DWORD* pdwSigLen);
		[DllImport(coredll, EntryPoint="CryptSignHash", SetLastError=true)] 
		private static extern bool CryptSignHashCe(IntPtr hHash, uint dwKeySpec, string sDescription, uint dwFlags, byte[] pbSignature, ref uint pdwSigLen);
		[DllImport(advapi32, EntryPoint="CryptSignHash", SetLastError=true)] 
		private static extern bool CryptSignHashXp(IntPtr hHash, uint dwKeySpec, string sDescription, uint dwFlags, byte[] pbSignature, ref uint pdwSigLen);
		
		///<summary>
		///This function decrypts and checks the integrity of the data in a DATA_BLOB 
		///structure. Usually, only a user with the same logon credentials as the encrypter 
		///can decrypt the data. In addition, the encryption and decryption must be done on 
		///the same computer. 
		///Note   An untrusted application can call the CryptUnprotectData function. The call 
		///will fail only if CRYPTPROTECT_SYSTEM is specified for the dwFlags parameter.
		///</summary>
		/// <remarks>
		/// works on smartPhone
		/// </remarks>
		public static bool CryptUnprotectData(ref CRYPTOAPI_BLOB pDataIn, ref IntPtr ppszDataDescr, IntPtr pOptionalEntropy, IntPtr pvReserved, IntPtr pPromptStruct, uint dwFlags, ref CRYPTOAPI_BLOB pDataOut)
		{
			if(System.Environment.OSVersion.Platform == PlatformID.WinCE)
				return CryptUnprotectDataCe(ref pDataIn, ref ppszDataDescr, pOptionalEntropy, pvReserved, pPromptStruct, dwFlags, ref pDataOut);
			else
				return CryptUnprotectDataXp(ref pDataIn, ref ppszDataDescr, pOptionalEntropy, pvReserved, pPromptStruct, dwFlags, ref pDataOut);
		}
		//BOOL WINAPI CryptUnprotectData(DATA_BLOB* pDataIn, LPWSTR* ppszDataDescr, DATA_BLOB* pOptionalEntropy, PVOID pvReserved, CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct, DWORD dwFlags, DATA_BLOB* pDataOut);
		[DllImport(coredll, EntryPoint="CryptUnprotectData", SetLastError=true)] 
		private static extern bool CryptUnprotectDataCe(ref CRYPTOAPI_BLOB pDataIn, ref IntPtr ppszDataDescr, IntPtr pOptionalEntropy, IntPtr pvReserved, IntPtr pPromptStruct, uint dwFlags, ref CRYPTOAPI_BLOB pDataOut); 
		[DllImport(crypt32, EntryPoint="CryptUnprotectData", SetLastError=true)] 
		private static extern bool CryptUnprotectDataXp(ref CRYPTOAPI_BLOB pDataIn, ref IntPtr ppszDataDescr, IntPtr pOptionalEntropy, IntPtr pvReserved, IntPtr pPromptStruct, uint dwFlags, ref CRYPTOAPI_BLOB pDataOut);

		///<summary>
		///This function verifies the signature of a hash object.
		///Before calling this function, the CryptCreateHash function must be called to get a 
		///handle to a hash object. The CryptHashData function or CryptHashSessionKey function 
		///is then used to add the data or session keys to the hash object.
		///After the call to the CryptVerifySignature function has been completed, only the 
		///CryptDestroyHash function can be called using the hHash handle.
		///</summary>
		/// <remarks>
		/// works on smartPhone
		/// </remarks>
		public static bool CryptVerifySignature(IntPtr hHash, byte[] pbSignature, uint dwSigLen, IntPtr hPubKey, string sDescription, uint dwFlags)
		{
			if(System.Environment.OSVersion.Platform == PlatformID.WinCE)
				return CryptVerifySignatureCe(hHash, pbSignature, dwSigLen, hPubKey, sDescription, dwFlags);
			else
				return CryptVerifySignatureXp(hHash, pbSignature, dwSigLen, hPubKey, sDescription, dwFlags);
		}
		//25   18 000097B0 CPVerifySignature 
		//BOOL WINAPI CryptVerifySignature(HCRYPTHASH hHash, BYTE* pbSignature, DWORD dwSigLen, HCRYPTKEY hPubKey, LPCTSTR sDescription, DWORD dwFlags);
		[DllImport(coredll, EntryPoint="CryptVerifySignature", SetLastError=true)] 
		private static extern bool CryptVerifySignatureCe(IntPtr hHash, byte[] pbSignature, uint dwSigLen, IntPtr hPubKey, string sDescription, uint dwFlags);
		[DllImport(advapi32, EntryPoint="CryptVerifySignature", SetLastError=true)] 
		private static extern bool CryptVerifySignatureXp(IntPtr hHash, byte[] pbSignature, uint dwSigLen, IntPtr hPubKey, string sDescription, uint dwFlags);
	}
}

⌨️ 快捷键说明

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