📄 crypto.cs
字号:
///<summary>
///This function finds the default cryptographic service provider (CSP) of a specified
///type either for the current user or the device. The name of the default CSP for
///the type specified in the dwProvType parameter is returned in the pszProvName buffer.
///</summary>
/// <remarks>
/// this did not work on smartPhone
/// can just use CryptAcquireContext and pass in alot of nulls
/// </remarks>
public static bool CryptGetDefaultProvider(uint dwProvType, ref uint pdwReserved, uint dwFlags, StringBuilder pszProvName, ref uint pcbProvName)
{
if(System.Environment.OSVersion.Platform == PlatformID.WinCE)
return CryptGetDefaultProviderCe(dwProvType, ref pdwReserved, dwFlags, pszProvName, ref pcbProvName);
else
return CryptGetDefaultProviderXp(dwProvType, ref pdwReserved, dwFlags, pszProvName, ref pcbProvName);
}
//BOOL WINAPI CryptGetDefaultProvider(DWORD dwProvType, DWORD* pdwReserved, DWORD dwFlags, LPTSTR pszProvName, DWORD* pcbProvName);
[DllImport(coredll, EntryPoint="CryptGetDefaultProvider", SetLastError=true)]
private static extern bool CryptGetDefaultProviderCe(uint dwProvType, ref uint pdwReserved, uint dwFlags, StringBuilder pszProvName, ref uint pcbProvName);
[DllImport(advapi32, EntryPoint="CryptGetDefaultProvider", SetLastError=true)]
private static extern bool CryptGetDefaultProviderXp(uint dwProvType, ref uint pdwReserved, uint dwFlags, StringBuilder pszProvName, ref uint pcbProvName);
///<summary>
///This function retrieves data that governs the operations of a hash object and
///retrieves the actual hash value.
///</summary>
/// <remarks>
/// mca / worked on smartPhone
/// </remarks>
public static bool CryptGetHashParam(IntPtr hHash, uint dwParam, byte[] pbData, ref uint pdwDataLen, uint dwFlags)
{
if(System.Environment.OSVersion.Platform == PlatformID.WinCE)
return CryptGetHashParamCe(hHash, dwParam, pbData, ref pdwDataLen, dwFlags);
else
return CryptGetHashParamXp(hHash, dwParam, pbData, ref pdwDataLen, dwFlags);
}
//13 C 00008B90 CPGetHashParam
//BOOL WINAPI CryptGetHashParam(HCRYPTHASH hHash, DWORD dwParam, BYTE* pbData, DWORD* pdwDataLen, DWORD dwFlags);
[DllImport(coredll, EntryPoint="CryptGetHashParam", SetLastError=true)]
private static extern bool CryptGetHashParamCe(IntPtr hHash, uint dwParam, byte[] pbData, ref uint pdwDataLen, uint dwFlags);
[DllImport(advapi32, EntryPoint="CryptGetHashParam", SetLastError=true)]
private static extern bool CryptGetHashParamXp(IntPtr hHash, uint dwParam, byte[] pbData, ref uint pdwDataLen, uint dwFlags);
///<summary>
///This function lets applications retrieve data that governs the operations of a key.
///In the Microsoft cryptographic service providers (CSPs), the base symmetric keying
///material is not obtainable by this or any other function.
///</summary>
/// <remarks>
/// works on smartPhone
/// </remarks>
public static bool CryptGetKeyParam(IntPtr hKey, uint dwParam, byte[] pbData, ref uint pdwDataLen, uint dwFlags)
{
if(System.Environment.OSVersion.Platform == PlatformID.WinCE)
return CryptGetKeyParamCe(hKey, dwParam, pbData, ref pdwDataLen, dwFlags);
else
return CryptGetKeyParamXp(hKey, dwParam, pbData, ref pdwDataLen, dwFlags);
}
//14 D 00007C2C CPGetKeyParam
//BOOL CRYPTFUNC CryptGetKeyParam(HCRYPTKEY hKey, DWORD dwParam, BYTE* pbData, DWORD* pdwDataLen, DWORD dwFlags);
[DllImport(coredll, EntryPoint="CryptGetKeyParam", SetLastError=true)]
private static extern bool CryptGetKeyParamCe(IntPtr hKey, uint dwParam, byte[] pbData, ref uint pdwDataLen, uint dwFlags);
[DllImport(advapi32, EntryPoint="CryptGetKeyParam", SetLastError=true)]
private static extern bool CryptGetKeyParamXp(IntPtr hKey, uint dwParam, byte[] pbData, ref uint pdwDataLen, uint dwFlags);
///<summary>
///This function retrieves parameters that govern the operations of a cryptographic
///service provider (CSP).
///</summary>
/// <remarks>
/// works on the smartPhone
/// </remarks>
public static bool CryptGetProvParam(IntPtr hProv, uint dwParam, byte[] pbData, ref uint pdwDataLen, uint dwFlags)
{
if(System.Environment.OSVersion.Platform == PlatformID.WinCE)
return CryptGetProvParamCe(hProv, dwParam, pbData, ref pdwDataLen, dwFlags);
else
return CryptGetProvParamXp(hProv, dwParam, pbData, ref pdwDataLen, dwFlags);
}
//15 E 00008130 CPGetProvParam
//BOOL WINAPI CryptGetProvParam(HCRYPTPROV hProv, DWORD dwParam, BYTE* pbData, DWORD* pdwDataLen, DWORD dwFlags);
[DllImport(coredll, EntryPoint="CryptGetProvParam", SetLastError=true)]
private static extern bool CryptGetProvParamCe(IntPtr hProv, uint dwParam, byte[] pbData, ref uint pdwDataLen, uint dwFlags);
[DllImport(advapi32, EntryPoint="CryptGetProvParam", SetLastError=true)]
private static extern bool CryptGetProvParamXp(IntPtr hProv, uint dwParam, byte[] pbData, ref uint pdwDataLen, uint dwFlags);
///<summary>
///This function retrieves a handle to a permanent user key pair, such as the user's
///signature key pair. This function also retrieves a handle to one of a user's two
///public/private key pairs. Only the owner of the public/private key pairs uses the
///function and only when the handle to a cryptographic service provider (CSP) and
///its associated key container is available. Use the CryptAcquireCertificatePrivateKey
///function if the user's certificate is available, but not the CSP handle.
///</summary>
/// <remarks>
/// mca / works on smartPhone
/// </remarks>
public static bool CryptGetUserKey(IntPtr hProv, uint dwKeySpec, out IntPtr phUserKey)
{
if(System.Environment.OSVersion.Platform == PlatformID.WinCE)
return CryptGetUserKeyCe(hProv, dwKeySpec, out phUserKey);
else
return CryptGetUserKeyXp(hProv, dwKeySpec, out phUserKey);
}
//16 F 000077D4 CPGetUserKey
//BOOL WINAPI CryptGetUserKey(HCRYPTPROV hProv, DWORD dwKeySpec, HCRYPTKEY* phUserKey);
[DllImport(coredll, EntryPoint="CryptGetUserKey", SetLastError=true)]
private static extern bool CryptGetUserKeyCe(IntPtr hProv, uint dwKeySpec, out IntPtr phUserKey);
[DllImport(advapi32, EntryPoint="CryptGetUserKey", SetLastError=true)]
private static extern bool CryptGetUserKeyXp(IntPtr hProv, uint dwKeySpec, out IntPtr phUserKey);
///<summary>
///This function adds data to a specified hash object. This function and the
///CryptHashSessionKey function can be called multiple times to compute the hash on
///long streams or on discontinuous streams.
///Before calling this function, the CryptCreateHash function must be called to create
///a handle to a hash object.
///</summary>
/// <remarks>
/// raCrypto, mca / worked on smartPhone
/// </remarks>
public static bool CryptHashData(IntPtr hHash, byte[] pbData, int dwDataLen, uint dwFlags)
{
if(System.Environment.OSVersion.Platform == PlatformID.WinCE)
return CryptHashDataCe(hHash, pbData, dwDataLen, dwFlags);
else
return CryptHashDataXp(hHash, pbData, dwDataLen, dwFlags);
}
//17 10 000052DC CPHashData
//BOOL WINAPI CryptHashData(HCRYPTHASH hHash, BYTE* pbData, DWORD dwDataLen, DWORD dwFlags);
[DllImport(coredll, EntryPoint="CryptHashData", SetLastError=true)]
private static extern bool CryptHashDataCe(IntPtr hHash, byte[] pbData, int dwDataLen, uint dwFlags);
[DllImport(advapi32, EntryPoint="CryptHashData", SetLastError=true)]
private static extern bool CryptHashDataXp(IntPtr hHash, byte[] pbData, int dwDataLen, uint dwFlags);
///<summary>
///This function computes the cryptographic hash of a session key object. This
///function can be called multiple times with the same hash handle to compute the hash
///of multiple keys. Calls to the CryptHashSessionKey function can be interspersed
///with calls to the CryptHashData function.
///Before calling this function, the CryptCreateHash function must be called to get a
///handle to a hash object.
///</summary>
/// <remarks>
/// works on smartPhone
/// </remarks>
public static bool CryptHashSessionKey(IntPtr hHash, IntPtr hKey, uint dwFlags)
{
if(System.Environment.OSVersion.Platform == PlatformID.WinCE)
return CryptHashSessionKeyCe(hHash, hKey, dwFlags);
else
return CryptHashSessionKeyXp(hHash, hKey, dwFlags);
}
//18 11 0000577C CPHashSessionKey
//BOOL WINAPI CryptHashSessionKey(HCRYPTHASH hHash, HCRYPTKEY hKey, DWORD dwFlags);
[DllImport(coredll, EntryPoint="CryptHashSessionKey", SetLastError=true)]
private static extern bool CryptHashSessionKeyCe(IntPtr hHash, IntPtr hKey, uint dwFlags);
[DllImport(advapi32, EntryPoint="CryptHashSessionKey", SetLastError=true)]
private static extern bool CryptHashSessionKeyXp(IntPtr hHash, IntPtr hKey, uint dwFlags);
///<summary>
///This function transfers a cryptographic key from a key binary large object (BLOB)
///to the cryptographic service provider (CSP). This function can be used to import
///an Schannel session key, regular session key, public key, or public/private key
///pair. For all but the public key, the key or key pair is encrypted.
///</summary>
/// <remarks>
/// mca / works on smartPhone
/// </remarks>
public static bool CryptImportKey(IntPtr hProv, byte[] pbData, uint dwDataLen, IntPtr hPubKey, uint dwFlags, out IntPtr phKey)
{
if(System.Environment.OSVersion.Platform == PlatformID.WinCE)
return CryptImportKeyCe(hProv, pbData, dwDataLen, hPubKey, dwFlags, out phKey);
else
return CryptImportKeyXp(hProv, pbData, dwDataLen, hPubKey, dwFlags, out phKey);
}
//19 12 00006DDC CPImportKey
//BOOL WINAPI CryptImportKey(HCRYPTPROV hProv, BYTE* pbData, DWORD dwDataLenHCRYPTKEY hPubKey, DWORD dwFlags, HCRYPTKEY* phKey);
[DllImport(coredll, EntryPoint="CryptImportKey", SetLastError=true)]
private static extern bool CryptImportKeyCe(IntPtr hProv, byte[] pbData, uint dwDataLen, IntPtr hPubKey, uint dwFlags, out IntPtr phKey);
[DllImport(advapi32, EntryPoint="CryptImportKey", SetLastError=true)]
private static extern bool CryptImportKeyXp(IntPtr hProv, byte[] pbData, uint dwDataLen, IntPtr hPubKey, uint dwFlags, out IntPtr phKey);
///<summary>
///This function performs encryption on the data in a DATA_BLOB structure. Typically,
///only a user with the same logon credentials as the encrypter can decrypt the data.
///In addition, the encryption and decryption usually must be done on the same
///computer. For information about exceptions, see the Remarks section.
///Note An untrusted application can call the CryptProtectData function. The call
///will fail only if CRYPTPROTECT_SYSTEM is specified for the dwFlags parameter.
///</summary>
/// <remarks>
/// works on smartPhone
/// </remarks>
public static bool CryptProtectData(ref CRYPTOAPI_BLOB pDataIn, StringBuilder szDataDescr, IntPtr pOptionalEntropy, IntPtr pvReserved, IntPtr pPromptStruct, uint dwFlags, ref CRYPTOAPI_BLOB pDataOut)
{
if(System.Environment.OSVersion.Platform == PlatformID.WinCE)
return CryptProtectDataCe(ref pDataIn, szDataDescr, pOptionalEntropy, pvReserved, pPromptStruct, dwFlags, ref pDataOut);
else
return CryptProtectDataXp(ref pDataIn, szDataDescr, pOptionalEntropy, pvReserved, pPromptStruct, dwFlags, ref pDataOut);
}
//BOOL WINAPI CryptProtectData(DATA_BLOB* pDataIn, LPCWSTR szDataDescr, DATA_BLOB* pOptionalEntropy, PVOID pvReserved, CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct, DWORD dwFlags, DATA_BLOB* pDataOut);
[DllImport(coredll, EntryPoint="CryptProtectData", SetLastError=true)]
private static extern bool CryptProtectDataCe(ref CRYPTOAPI_BLOB pDataIn, StringBuilder szDataDescr, IntPtr pOptionalEntropy, IntPtr pvReserved, IntPtr pPromptStruct, uint dwFlags, ref CRYPTOAPI_BLOB pDataOut);
[DllImport(crypt32, EntryPoint="CryptProtectData", SetLastError=true)]
private static extern bool CryptProtectDataXp(ref CRYPTOAPI_BLOB pDataIn, StringBuilder szDataDescr, IntPtr pOptionalEntropy, IntPtr pvReserved, IntPtr pPromptStruct, uint dwFlags, ref CRYPTOAPI_BLOB pDataOut);
///<summary>
///This function releases the handle to a cryptographic service provider (CSP) and
///the key container. At each call to this function, the reference count on the CSP
///is reduced by one. When the reference count reaches zero, the context is fully
///released and it can no longer be used by any function in the application.
///The application calls this function when it is finished using the CSP. After this
///function is called, the CSP handle specified by the hProv parameter is no longer
///valid; however, the function does not destroy either the key container or any key
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -