Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crypt file

Status
Not open for further replies.

mata1986

Programmer
Joined
Aug 6, 2013
Messages
1
Location
US
Hi,
I'm using Delphi XE.

I need to sign file with RSA cert from smart card, type PKCS7, p7s.
Problem is that I can't access private key at card.

Could you see what is wrong..

This is code:

Code:
var
  signPara: CRYPT_SIGN_MESSAGE_PARA;//CRYPT_SIGN_MESSAGE_PARA ;
  hashAlgorithm:     CRYPT_ALGORITHM_IDENTIFIER ;
  hStore:     HCERTSTORE ;
  pSignerContext:     PCCERT_CONTEXT ;
  lpData :Pointer; //array of PBYTE;//;
  dwDataSize : Pointer; //DWORD;//;
  dwDS: DWORD;
  bResult:boolean;
  lpSignedBlob:PBYTE;
  dwSignedBlobSize:DWORD;
  hFile, hTempFile:THandle ;
  dwWriteByte:DWORD;
  cToBeSigned:DWORD;
  size_new: DWORD;
 
  pStreamIn, tpStreamIn : TMemoryStream ;
  pStreamOut, tpStreamOut : TMemoryStream ;
  file_name:string;
 
  ret: Integer;
  Data: array [0..MAXBYTE] of AnsiChar;
  Cert: array [0..MAX_BUFFER_LEN] of AnsiChar;
  Lng: UINT;
  PIN: array[0..19] of AnsiChar;
  Rez: AnsiString;
  citac: TCitac;
  pwszCertSubject :PWideChar;
 
 const
  CERT_STORE_NAME = WideString('MY');
begin
hStore := CertOpenSystemStore (0, CERT_STORE_NAME);
                                                                                                                              
     pSignerContext := CertFindCertificateInStore (hStore, (PKCS_7_ASN_ENCODING or X509_ASN_ENCODING), 0, CERT_FIND_SUBJECT_STR, nil, nil);
 
   CryptAcquireContext (@hStore, nil, nil, PROV_RSA_FULL,0);//CRYPT_VERIFYCONTEXT) ;
 
     ZeroMemory (@hashAlgorithm, sizeof (CRYPT_ALGORITHM_IDENTIFIER));
     hashAlgorithm.pszObjId := szOID_RSA_MD5;
 
     ........
 
   CryptSignMessage(@signPara, true, cToBeSigned,  @lpData,  @dwDataSize, nil, @dwSignedBlobSize);

I think that problem is in CryptAcquireContext ()...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top