Advertisement
carlosfeitozafilho

CryptoAPI x CNG

Apr 22nd, 2020
1,177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.24 KB | None | 0 0
  1. var
  2.   Provider: NCRYPT_PROV_HANDLE;
  3.   Reader: PByte;
  4.   ReaderSize: DWORD;
  5.   MemorySize: DWORD;
  6. begin
  7.   // Get a handle to the smartcard reader specific provider
  8.   Status := NCryptOpenStorageProvider(@Provider
  9.                                      ,'SafeSign Standard RSA and AES Cryptographic Service Provider'
  10.                                      ,0); // returns ERROR_SUCCESS
  11.   // Convert the name of the reader to a PByte
  12.   UnicodeStringToBinary('Giesecke & Devrient GmbH StarSign CUT 0',Reader,ReaderSize);
  13.  
  14.   // Inform the name of the reader to the CNG
  15.   Status := NCryptSetProperty(Provider
  16.                              ,NCRYPT_READER_PROPERTY
  17.                              ,Reader
  18.                              ,ReaderSize
  19.                              ,0); // returns ERROR_SUCCESS
  20.  
  21.   MemorySize := SizeOf(HCERTSTORE);
  22.  
  23.   // Try to get the size needed to a variable of type HCERTSTORE.
  24.   // This is the first step before get the certificate store
  25.   Status := NCryptGetProperty(Provider
  26.                              ,NCRYPT_USER_CERTSTORE_PROPERTY
  27.                              ,nil
  28.                              ,0
  29.                              ,@MemorySize
  30.                              ,0); //Returns 0x80090029 (NTE_NOT_SUPPORTED)
  31. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement