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:
I think that problem is in CryptAcquireContext ()...
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 ()...