INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Crypt file

Crypt file

(OP)
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 --> delphi

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 ()...

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close