public static void SetKeyParameter(SafeKeyHandleImpl keyHandle, int keyParamId, byte[] keyParamValue) { if (!CryptoApi.CryptSetKeyParam(keyHandle, (uint)keyParamId, keyParamValue, 0)) { throw CreateWin32Error(); } }
public static void HashKeyExchange(SafeHashHandleImpl hashHandle, SafeKeyHandleImpl keyExchangeHandle) { if (!CryptoApi.CryptHashSessionKey(hashHandle, keyExchangeHandle, 0)) { throw CreateWin32Error(); } }
public static bool VerifySign(SafeProvHandleImpl providerHandle, SafeKeyHandleImpl keyHandle, byte[] hashValue, byte[] signatureValue) { using (var hashHandle = SetupHashAlgorithm(providerHandle, hashValue)) { return(CryptoApi.CryptVerifySignature(hashHandle, signatureValue, (uint)signatureValue.Length, keyHandle, null, 0)); } }
private static void SetKeyParameterString(SafeKeyHandleImpl keyHandle, int keyParamId, string keyParamValue) { var stringDataBytes = Encoding.GetEncoding(0).GetBytes(keyParamValue); if (!CryptoApi.CryptSetKeyParam(keyHandle, (uint)keyParamId, stringDataBytes, 0)) { throw CreateWin32Error(); } }
public static void SetKeyParameterInt32(SafeKeyHandleImpl keyHandle, int keyParamId, int keyParamValue) { var dwDataBytes = BitConverter.GetBytes(keyParamValue); if (!CryptoApi.CryptSetKeyParam(keyHandle, (uint)keyParamId, dwDataBytes, 0)) { throw CreateWin32Error(); } }
public static byte[] GetKeyParameter(SafeKeyHandleImpl keyHandle, uint keyParamId) { uint dataLength = 0; if (!CryptoApi.CryptGetKeyParam(keyHandle, keyParamId, null, ref dataLength, 0)) { throw CreateWin32Error(); } var dataBytes = new byte[dataLength]; if (!CryptoApi.CryptGetKeyParam(keyHandle, keyParamId, dataBytes, ref dataLength, 0)) { throw CreateWin32Error(); } return(dataBytes); }
public static byte[] ExportCspBlob(SafeKeyHandleImpl symKeyHandle, SafeKeyHandleImpl keyExchangeHandle, int blobType) { uint exportedKeyLength = 0; if (!CryptoApi.CryptExportKey(symKeyHandle, keyExchangeHandle, (uint)blobType, 0, null, ref exportedKeyLength)) { throw CreateWin32Error(); } var exportedKeyBytes = new byte[exportedKeyLength]; if (!CryptoApi.CryptExportKey(symKeyHandle, keyExchangeHandle, (uint)blobType, 0, exportedKeyBytes, ref exportedKeyLength)) { throw CreateWin32Error(); } return(exportedKeyBytes); }
public static int GetKeyParameterInt32(SafeKeyHandleImpl keyHandle, uint keyParamId) { const int doubleWordSize = 4; uint dwDataLength = doubleWordSize; var dwDataBytes = new byte[doubleWordSize]; if (!CryptoApi.CryptGetKeyParam(keyHandle, keyParamId, dwDataBytes, ref dwDataLength, 0)) { throw CreateWin32Error(); } if (dwDataLength != doubleWordSize) { throw ExceptionUtility.CryptographicException(Constants.NTE_BAD_DATA); } return(BitConverter.ToInt32(dwDataBytes, 0)); }
public static extern bool CryptDuplicateKey([In] IntPtr hKey, [In] byte[] pdwReserved, [In] uint dwFlags, [In][Out] ref SafeKeyHandleImpl phKey);
public static extern bool CryptDeriveKey([In] SafeProvHandleImpl hProv, [In] uint Algid, [In] SafeHashHandleImpl hBaseData, [In] uint dwFlags, [In][Out] ref SafeKeyHandleImpl phKey);
public static extern bool CryptGetUserKey([In] SafeProvHandleImpl hProv, [In] uint dwKeySpec, [In][Out] ref SafeKeyHandleImpl phUserKey);
public static extern bool CryptGenKey([In] SafeProvHandleImpl hProv, [In] uint Algid, [In] uint dwFlags, [In][Out] ref SafeKeyHandleImpl phKey);
public static extern bool CryptEncrypt([In] SafeKeyHandleImpl hKey, [In] SafeHashHandleImpl hHash, [In][MarshalAs(UnmanagedType.Bool)] bool Final, [In] uint dwFlags, [In][Out] byte[] pbData, ref uint pdwDataLen, [In] uint dwBufLen);
public static SafeKeyHandleImpl DuplicateKey(SafeKeyHandleImpl sourceKeyHandle) { return(DuplicateKey(sourceKeyHandle.DangerousGetHandle())); }
public static extern bool CryptVerifySignature([In] SafeHashHandleImpl hHash, [In][Out] byte[] pbSignature, uint pdwSigLen, [In] SafeKeyHandleImpl hPubKey, [MarshalAs(UnmanagedType.LPStr)] StringBuilder sDescription, [In] uint dwFlags);
public static extern bool CryptExportKey([In] SafeKeyHandleImpl hKey, [In] SafeKeyHandleImpl hExpKey, [In] uint dwBlobType, [In] uint dwFlags, [Out] byte[] pbData, ref uint pdwDataLen);
public static extern bool CryptGetKeyParam([In] SafeKeyHandleImpl hKey, [In] uint dwParam, [In][Out] byte[] pbData, ref uint pdwDataLen, [In] uint dwFlags);
private static string GetKeyParameterString(SafeKeyHandleImpl keyHandle, uint keyParamId) { var paramValue = GetKeyParameter(keyHandle, keyParamId); return(BytesToString(paramValue)); }
public static extern bool CryptSetKeyParam([In] SafeKeyHandleImpl hKey, [In] uint dwParam, [In] byte[] pbData, [In] uint dwFlags);
public static int ImportCspBlob(byte[] importedKeyBytes, SafeProvHandleImpl providerHandle, SafeKeyHandleImpl publicKeyHandle, out SafeKeyHandleImpl keyExchangeHandle) { var dwFlags = MapCspKeyFlags(CspProviderFlags.NoFlags); var keyExchangeRef = SafeKeyHandleImpl.InvalidHandle; if (!CryptoApi.CryptImportKey(providerHandle, importedKeyBytes, (uint)importedKeyBytes.Length, publicKeyHandle, dwFlags, ref keyExchangeRef)) { throw CreateWin32Error(); } var keyNumberMask = BitConverter.ToInt32(importedKeyBytes, 4) & 0xE000; var keyNumber = (keyNumberMask == 0xA000) ? Constants.AT_KEYEXCHANGE : Constants.AT_SIGNATURE; keyExchangeHandle = keyExchangeRef; return(keyNumber); }
public static extern bool CryptImportKey([In] SafeProvHandleImpl hCryptProv, [In] byte[] pbData, [In] uint dwDataLen, [In] SafeKeyHandleImpl hPubKey, [In] uint dwFlags, [In][Out] ref SafeKeyHandleImpl phKey);
public static extern bool CryptHashSessionKey([In] SafeHashHandleImpl hHash, [In] SafeKeyHandleImpl hKey, [In] uint dwFlags);
public static extern bool CryptCreateHash([In] SafeProvHandleImpl hProv, [In] uint Algid, [In] SafeKeyHandleImpl hKey, [In] uint dwFlags, [In][Out] ref SafeHashHandleImpl phHash);
public static SafeHashHandleImpl CreateHashImit(SafeProvHandleImpl providerHandle, SafeKeyHandleImpl symKeyHandle) { var hashImitHandle = SafeHashHandleImpl.InvalidHandle; if (!CryptoApi.CryptCreateHash(providerHandle, Constants.CALG_G28147_IMIT, symKeyHandle, 0, ref hashImitHandle)) { throw CreateWin32Error(); } return(hashImitHandle); }