Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

#include "rutoken/pki-core-cpp.h"
#include <iostream>

using namespace rutoken::pkicore;

class PkiCore
	explicit PkiCore(const std::string& path)
	~PkiCore() throw()
		try {
		catch (...) {
int main()

	PkiCore p("./");

	auto deviceList = Pkcs11Device::enumerate();

	for (auto& d : deviceList)
		std::cout << d.getLabel() << std::endl;
	auto keyA = deviceList.front().generateKeyPair(Pkcs11Device::Gost34102001KeyGenParams(Gost34102001Paramset::a));
	X500Dn x500Dn;
	// русские символы в кодировке utf8: смотрите
	x500Dn.setRdn(X500Dn::RdnId::commonName, u8"Иванов Иван Иванович"); 
	x500Dn.setRdn(X500Dn::RdnId::surname, "Ivanov");
	x500Dn.setRdn(X500Dn::RdnId::givenName, "Ivan");
	x500Dn.setRdn(X500Dn::RdnId::title, "king");
	x500Dn.setRdn(X500Dn::RdnId::pseudonym, "Ivan");
	x500Dn.setRdn(X500Dn::RdnId::emailAddress, "");
	x500Dn.setRdn(X500Dn::RdnId::countryName, "RU");
	x500Dn.setRdn(X500Dn::RdnId::localityName, "Moscow");
	x500Dn.setRdn(X500Dn::RdnId::stateOrProvinceName, "Moscow");
	x500Dn.setRdn(X500Dn::RdnId::organization, "Aktiv");
	x500Dn.setRdn(X500Dn::RdnId::organizationalUnit, "IT");
	x500Dn.setRdn(X500Dn::RdnId::street, "STREET");
	x500Dn.setRdn(X500Dn::RdnId::ogrn, "12345678987")
		.setRdn(X500Dn::RdnId::ogrnip, "12345678987")
		.setRdn(X500Dn::RdnId::snils, "12345678987")
		.setRdn(X500Dn::RdnId::inn, "12345678987");
	unsigned char customExtensionASN1Data[] = {
		0x0C, 0x33, 0x30, 0x30, 0x43, 0x41, 0x30, 0x31,
		0x37, 0x38, 0x69, 0xD0, 0x90, 0xD0, 0xA0, 0xD0,
		0x9C, 0x20, 0xD0, 0x98, 0xD0, 0xBD, 0xD0, 0xB8,
		0xD1, 0x86, 0xD0, 0xB8, 0xD0, 0xB0, 0xD0, 0xBB,
		0xD0, 0xB8, 0xD0, 0xB7, 0xD0, 0xB0, 0xD1, 0x86,
		0xD0, 0xB8, 0xD0, 0xB8, 0x20, 0xD0, 0xA2, 0xD0,
		0x95, 0xD0, 0xA1, 0xD0, 0xA2,
	unsigned char cRLDistributionPointsASN1Data[] = {
		0x30, 0x2A, 0x30, 0x28, 0xA0, 0x26, 0xA0, 0x24,
		0x86, 0x22, 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F,
		0x2F, 0x77, 0x77, 0x77, 0x2E, 0x73, 0x62, 0x72,
		0x66, 0x2E, 0x72, 0x75, 0x2F, 0x63, 0x61, 0x2F,
		0x30, 0x30, 0x30, 0x30, 0x78, 0x35, 0x30, 0x39,
		0x2E, 0x63, 0x72, 0x6C

	Pkcs10RequestInfo requestInfo;
			.addExtendedKeyUsageByOid("1.2.643.") // CryptoPro RA user
			.addCustomExtension("1.2.643.", customExtensionASN1Data, sizeof(customExtensionASN1Data), false)
			.addCustomExtension("", cRLDistributionPointsASN1Data,
				sizeof(cRLDistributionPointsASN1Data), true) // CRL Distribution Points
	Pkcs10Request request = createPkcs10Request(keyA, requestInfo);
	auto data = request.toPem();
	std::cout << data << std::endl;

	return 0;
  • No labels