Статус: Активный участник
Группы: Участники
Зарегистрирован: 06.03.2012(UTC) Сообщений: 177
Сказал(а) «Спасибо»: 57 раз Поблагодарили: 11 раз в 8 постах
|
Автор: mata1986  Yes, they are <> nil, always different values. OK. CryptAcquireContext (@hStore, PWideChar(citac.ReaderId), PWideChar(citac.CardId), PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);//CRYPT_VERIFYCONTEXT) ; This option is intended for applications that are using ephemeral keys, or applications that do not require access to persisted private keys, such as applications that perform only hashing, encryption, and digital signature verification. Only applications that create signatures or decrypt messages need access to a private key. In most cases, this flag should be set. For file-based CSPs, when this flag is set, the pszContainer parameter must be set to NULL. The application has no access to the persisted private keys of public/private key pairs. When this flag is set, temporary public/private key pairs can be created, but they are not persisted. For hardware-based CSPs, such as a smart card CSP, if the pszContainer parameter is NULL or blank, this flag implies that no access to any keys is required, and that no UI should be presented to the user. This form is used to connect to the CSP to query its capabilities but not to actually use its keys. If the pszContainer parameter is not NULL and not blank, then this flag implies that access to only the publicly available information within the specified container is required. The CSP should not ask for a PIN. Attempts to access private information (for example, the CryptSignHash function) will fail. When CryptAcquireContext is called, many CSPs require input from the owning user before granting access to the private keys in the key container. For example, the private keys can be encrypted, requiring a password from the user before they can be used. However, if the CRYPT_VERIFYCONTEXT flag is specified, access to the private keys is not required and the user interface can be bypassed. It's operation not a check sign and need private key.
|
|
|
|
Статус: Участник
Группы: Участники
Зарегистрирован: 02.08.2013(UTC) Сообщений: 11
|
I tried with other dwFlags, or dwFlags=0, but it doesn't work. Could you tell me how can I access to private key from smart card?
|
|
|
|
Статус: Активный участник
Группы: Участники
Зарегистрирован: 14.07.2008(UTC) Сообщений: 1,287   Откуда: Краснодар Сказал «Спасибо»: 81 раз Поблагодарили: 72 раз в 60 постах
|
We are from Russia! Or not?
|
 1 пользователь поблагодарил Laroux за этот пост.
|
|
|
Статус: Участник
Группы: Участники
Зарегистрирован: 02.08.2013(UTC) Сообщений: 11
|
|
|
|
|
Статус: Активный участник
Группы: Участники
Зарегистрирован: 14.07.2008(UTC) Сообщений: 1,287   Откуда: Краснодар Сказал «Спасибо»: 81 раз Поблагодарили: 72 раз в 60 постах
|
why...))) Why are you in our cryptography?
|
|
|
|
Статус: Активный участник
Группы: Участники
Зарегистрирован: 22.01.2008(UTC) Сообщений: 671   Откуда: Йошкар-Ола Сказал «Спасибо»: 3 раз Поблагодарили: 95 раз в 68 постах
|
Автор: Laroux  why...))) Why are you in our cryptography? Because we are the best, you should know that already :) |
С уважением, Юрий Строжевский |
|
|
|
Статус: Активный участник
Группы: Участники
Зарегистрирован: 22.01.2008(UTC) Сообщений: 671   Откуда: Йошкар-Ола Сказал «Спасибо»: 3 раз Поблагодарили: 95 раз в 68 постах
|
The root cause for the initial problem could be that the certificate found by "CertFindCertificateInStore" has no associated private key. That is why "CryptSignMessage" is unable to sign a message. Here is my very old cryptographic example for the high-level signing (but it's on C++): Код:void HighLevel_Sign(BYTE** signature, DWORD* count)
{
_out<<std::endl;
_out<<TEXT(" High-level sign ")<<std::endl;
_out<<TEXT("================================")<<std::endl;
// Get certificates for receivers
HCERTSTORE hSystemStore;
if(!(hSystemStore = CertOpenSystemStore(NULL, TEXT("MY"))))
{
Error( TEXT("CertOpenSystemStore") );
return;
}
_out<<TEXT("System store has opened")<<std::endl;
PCCERT_CONTEXT pCert=NULL;
while(pCert=CertEnumCertificatesInStore(hSystemStore,pCert))
{
// Choose the very first certificate with specified algorithm and associated private key
if(!strcmp(pCert->pCertInfo->SubjectPublicKeyInfo.Algorithm.pszObjId, "1.2.840.113549.1.1.1"))
{
DWORD dwKeySpec;
HCRYPTPROV hProv;
if(CryptAcquireCertificatePrivateKey(pCert,0,NULL,&hProv,&dwKeySpec,NULL))
{
CryptReleaseContext(hProv,0);
break;
}
}
}
_out<<TEXT("Certificate found")<<std::endl;
//---
CRYPT_SIGN_MESSAGE_PARA SignPara;
ZeroMemory(&SignPara,sizeof(SignPara));
SignPara.cbSize=sizeof(SignPara);
SignPara.dwMsgEncodingType=X509_ASN_ENCODING | PKCS_7_ASN_ENCODING;
SignPara.HashAlgorithm.pszObjId=(LPSTR)CertAlgIdToOID(CALG_MD5);
SignPara.pSigningCert=pCert;
SignPara.cMsgCert=1;
SignPara.rgpMsgCert=&pCert;
char string[]="Test";
const BYTE* DataArray[]={(BYTE*)string};
DWORD SizeArray[]={strlen(string)};
*count=0;
if(!CryptSignMessage(&SignPara,true,1,DataArray,SizeArray,NULL,count))
{
Error( TEXT("CryptSignMessage") );
return;
}
*signature=static_cast<BYTE*>(malloc(*count));
if(!CryptSignMessage(&SignPara,true,1,DataArray,SizeArray,*signature,count))
{
Error( TEXT("CryptSignMessage") );
return;
}
_out<<TEXT("Signature content is received")<<std::endl;
// Free cryptographic contexts
CertFreeCertificateContext(pCert);
CertCloseStore(hSystemStore,0);
}
Hope it's will help you. |
С уважением, Юрий Строжевский |
|
|
|
Статус: Участник
Группы: Участники
Зарегистрирован: 02.08.2013(UTC) Сообщений: 11
|
Thanks, I'm try it now...
Can you tell me how to use *signature=static_cast<BYTE*>(malloc(*count)); in delphi??
|
|
|
|
Статус: Сотрудник
Группы: Участники
Зарегистрирован: 26.07.2011(UTC) Сообщений: 13,770   Сказал «Спасибо»: 579 раз Поблагодарили: 2307 раз в 1807 постах
|
Автор: mata1986  Thanks, I'm try it now...
Can you tell me how to use *signature=static_cast<BYTE*>(malloc(*count)); in delphi?? GetMem() |
|
|
|
|
Статус: Сотрудник
Группы: Участники
Зарегистрирован: 26.07.2011(UTC) Сообщений: 13,770   Сказал «Спасибо»: 579 раз Поблагодарили: 2307 раз в 1807 постах
|
or AllocMem Цитата: function AllocMem(Size: Cardinal): Pointer; begin GetMem(Result, Size); FillChar(Result^, Size, 0); end;
|
|
|
|
|
Быстрый переход
Вы не можете создавать новые темы в этом форуме.
Вы не можете отвечать в этом форуме.
Вы не можете удалять Ваши сообщения в этом форуме.
Вы не можете редактировать Ваши сообщения в этом форуме.
Вы не можете создавать опросы в этом форуме.
Вы не можете голосовать в этом форуме.
Important Information:
The Форум КриптоПро uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close