private static extern bool CryptCreateHash(IntPtr hProv, ALG_ID algid, IntPtr hKey, uint dwFlags, ref IntPtr phHash);
private static bool SignVerifyFile(HCRYPTPROV hProv, HCRYPTKEY hPubKey, CertKeySpec dwKeySpec, ALG_ID HashAlgId, string szFileToSign, string szSigFile, bool fSign) { const uint BUFFER_SIZE = 4096; uint dwSignature; bool fResult; bool fReturn = false; try { // Open Data file using var hDataFile = CreateFile(szFileToSign, Kernel32.FileAccess.GENERIC_READ, 0, default, FileMode.Open, FileFlagsAndAttributes.FILE_ATTRIBUTE_NORMAL); if (hDataFile.IsInvalid) { MyPrintf(("CreateFile failed with %d\n"), GetLastError()); throw new Exception(); } // Open/Create signature file using var hSigFile = CreateFile(szSigFile, Kernel32.FileAccess.GENERIC_READ | Kernel32.FileAccess.GENERIC_WRITE, 0, default, FileMode.Open, FileFlagsAndAttributes.FILE_ATTRIBUTE_NORMAL); if (hSigFile.IsInvalid) { MyPrintf(("CreateFile failed with %d\n"), GetLastError()); throw new Exception(); } SafeHCRYPTHASH hHash; // Create Hash fResult = CryptCreateHash(hProv, HashAlgId, default, 0, out hHash);
public static extern bool CryptCreateHash(IntPtr hProv, ALG_ID Algid, IntPtr hKey, uint dwFlags, out IntPtr phHash);
public static extern bool CryptDeriveKey(IntPtr hProv, ALG_ID Algid, IntPtr hBaseData, uint dwFlags, ref IntPtr phKey);
public static extern bool CryptGenKey( [In] IntPtr hProv, [In] ALG_ID Algid, [In] uint dwFlags, [Out] out IntPtr phKey );