Ключевое слово в защите информации
КЛЮЧЕВОЕ СЛОВО
в защите информации
Получить ГОСТ TLS-сертификат для домена (SSL-сертификат)
Добро пожаловать, Гость! Чтобы использовать все возможности Вход или Регистрация.

Уведомление

Icon
Error

3 Страницы<123>
Опции
К последнему сообщению К первому непрочитанному
Offline MCR  
#11 Оставлено : 6 августа 2013 г. 9:49:38(UTC)
MCR

Статус: Активный участник

Группы: Участники
Зарегистрирован: 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.


Offline mata1986  
#12 Оставлено : 6 августа 2013 г. 13:55:08(UTC)
mata1986

Статус: Участник

Группы: Участники
Зарегистрирован: 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?
Offline Laroux  
#13 Оставлено : 6 августа 2013 г. 14:04:29(UTC)
Laroux

Статус: Активный участник

Группы: Участники
Зарегистрирован: 14.07.2008(UTC)
Сообщений: 1,287
Мужчина
Российская Федерация
Откуда: Краснодар

Сказал «Спасибо»: 81 раз
Поблагодарили: 72 раз в 60 постах
We are from Russia! Or not?Anxious
thanks 1 пользователь поблагодарил Laroux за этот пост.
Андрей * оставлено 06.08.2013(UTC)
Offline mata1986  
#14 Оставлено : 6 августа 2013 г. 21:19:48(UTC)
mata1986

Статус: Участник

Группы: Участники
Зарегистрирован: 02.08.2013(UTC)
Сообщений: 11

no, I'm not... why?
Offline Laroux  
#15 Оставлено : 7 августа 2013 г. 0:53:41(UTC)
Laroux

Статус: Активный участник

Группы: Участники
Зарегистрирован: 14.07.2008(UTC)
Сообщений: 1,287
Мужчина
Российская Федерация
Откуда: Краснодар

Сказал «Спасибо»: 81 раз
Поблагодарили: 72 раз в 60 постах
why...))) Why are you in our cryptography?
Offline Юрий  
#16 Оставлено : 7 августа 2013 г. 7:32:48(UTC)
Юрий

Статус: Активный участник

Группы: Участники
Зарегистрирован: 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 :)
С уважением,
Юрий Строжевский
Offline Юрий  
#17 Оставлено : 7 августа 2013 г. 7:47:37(UTC)
Юрий

Статус: Активный участник

Группы: Участники
Зарегистрирован: 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.
С уважением,
Юрий Строжевский
Offline mata1986  
#18 Оставлено : 8 августа 2013 г. 14:36:30(UTC)
mata1986

Статус: Участник

Группы: Участники
Зарегистрирован: 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??
Offline Андрей Писарев  
#19 Оставлено : 8 августа 2013 г. 14:38:54(UTC)
Андрей *

Статус: Сотрудник

Группы: Участники
Зарегистрирован: 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()
Техническую поддержку оказываем тут
Наша база знаний
Offline Андрей Писарев  
#20 Оставлено : 8 августа 2013 г. 14:40:49(UTC)
Андрей *

Статус: Сотрудник

Группы: Участники
Зарегистрирован: 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;
Техническую поддержку оказываем тут
Наша база знаний
RSS Лента  Atom Лента
Пользователи, просматривающие эту тему
Guest
3 Страницы<123>
Быстрый переход  
Вы не можете создавать новые темы в этом форуме.
Вы не можете отвечать в этом форуме.
Вы не можете удалять Ваши сообщения в этом форуме.
Вы не можете редактировать Ваши сообщения в этом форуме.
Вы не можете создавать опросы в этом форуме.
Вы не можете голосовать в этом форуме.