<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Форум Рутокен &mdash; Генерация пары]]></title>
	<link rel="self" href="https://forum.rutoken.ru/feed/atom/topic/2323/" />
	<updated>2015-10-24T12:55:03Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.rutoken.ru/topic/2323/</id>
		<entry>
			<title type="html"><![CDATA[Re: Генерация пары]]></title>
			<link rel="alternate" href="https://forum.rutoken.ru/post/8950/#p8950" />
			<content type="html"><![CDATA[<p>ура - нашел ошибку. Все получилось.</p>]]></content>
			<author>
				<name><![CDATA[Oleg Shishkin]]></name>
				<uri>https://forum.rutoken.ru/user/9901/</uri>
			</author>
			<updated>2015-10-24T12:55:03Z</updated>
			<id>https://forum.rutoken.ru/post/8950/#p8950</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Генерация пары]]></title>
			<link rel="alternate" href="https://forum.rutoken.ru/post/8949/#p8949" />
			<content type="html"><![CDATA[<p>Попытался генерировать пару Gost3410 по исходникам<br />&nbsp; &nbsp; &nbsp; &nbsp; final CK_MECHANISM mechanism = new CK_MECHANISM(RtPkcs11Constants.CKM_GOSTR3410_KEY_PAIR_GEN);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; final CK_ATTRIBUTE[] publicKeyTemplate = (CK_ATTRIBUTE[]) (new CK_ATTRIBUTE()).toArray(9);<br />&nbsp; &nbsp; &nbsp; &nbsp; publicKeyTemplate[0].set(Pkcs11Constants.CKA_CLASS, Pkcs11Constants.CKO_PUBLIC_KEY);<br />&nbsp; &nbsp; &nbsp; &nbsp; publicKeyTemplate[1].set(Pkcs11Constants.CKA_LABEL, &quot;Public Key&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; publicKeyTemplate[2].set(Pkcs11Constants.CKA_ID, &quot;GOST R 34.10-2001 sample keypair 1 ID (Aktiv Co.)&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; publicKeyTemplate[3].set(Pkcs11Constants.CKA_KEY_TYPE, RtPkcs11Constants.CKK_GOSTR3410);<br />&nbsp; &nbsp; &nbsp; &nbsp; publicKeyTemplate[4].set(Pkcs11Constants.CKA_ENCRYPT, true);<br />&nbsp; &nbsp; &nbsp; &nbsp; publicKeyTemplate[5].set(Pkcs11Constants.CKA_TOKEN, true);<br />&nbsp; &nbsp; &nbsp; &nbsp; publicKeyTemplate[6].set(Pkcs11Constants.CKA_PRIVATE, false);<br />&nbsp; &nbsp; &nbsp; &nbsp; publicKeyTemplate[7].set(Pkcs11Constants.CKA_DERIVE, true);<br />&nbsp; &nbsp; &nbsp; &nbsp; publicKeyTemplate[8].set(RtPkcs11Constants.CKA_GOSTR3410_PARAMS, RtPkcs11Constants.GOST3410_PARAMS_OID);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; final CK_ATTRIBUTE[] privateKeyTemplate = (CK_ATTRIBUTE[]) (new CK_ATTRIBUTE()).toArray(10);<br />&nbsp; &nbsp; &nbsp; &nbsp; privateKeyTemplate[0].set(Pkcs11Constants.CKA_CLASS, Pkcs11Constants.CKO_PRIVATE_KEY);<br />&nbsp; &nbsp; &nbsp; &nbsp; privateKeyTemplate[1].set(Pkcs11Constants.CKA_LABEL, &quot;Private Key&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; privateKeyTemplate[2].set(Pkcs11Constants.CKA_ID, &quot;GOST R 34.10-2001 sample keypair 1 ID (Aktiv Co.)&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; privateKeyTemplate[3].set(Pkcs11Constants.CKA_KEY_TYPE, RtPkcs11Constants.CKK_GOSTR3410);<br />&nbsp; &nbsp; &nbsp; &nbsp; privateKeyTemplate[4].set(Pkcs11Constants.CKA_DECRYPT, true);<br />&nbsp; &nbsp; &nbsp; &nbsp; privateKeyTemplate[5].set(Pkcs11Constants.CKA_TOKEN, true);<br />&nbsp; &nbsp; &nbsp; &nbsp; privateKeyTemplate[6].set(Pkcs11Constants.CKA_PRIVATE, true);<br />&nbsp; &nbsp; &nbsp; &nbsp; privateKeyTemplate[7].set(Pkcs11Constants.CKA_DERIVE, true);<br />&nbsp; &nbsp; &nbsp; &nbsp; privateKeyTemplate[8].set(RtPkcs11Constants.CKA_GOSTR3410_PARAMS, RtPkcs11Constants.GOST3410_PARAMS_OID);<br />&nbsp; &nbsp; &nbsp; &nbsp; privateKeyTemplate[9].set(RtPkcs11Constants.CKA_GOSTR3411_PARAMS, RtPkcs11Constants.GOST3411_PARAMS_OID);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; NativeLongByReference phPublicKey = new NativeLongByReference(new NativeLong(0));<br />&nbsp; &nbsp; &nbsp; &nbsp; NativeLongByReference phPrivateKey = new NativeLongByReference(new NativeLong(0));</p><p>&nbsp; &nbsp; &nbsp; &nbsp; NativeLong rv = Pkcs11Constants.CKR_OK;<br />&nbsp; &nbsp; &nbsp; &nbsp; rv = mPkcs11.C_GenerateKeyPair(<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mSession,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mechanism,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; publicKeyTemplate,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new NativeLong(publicKeyTemplate.length),<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; privateKeyTemplate,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new NativeLong(privateKeyTemplate.length),<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; phPublicKey,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; phPrivateKey);<br />&nbsp; &nbsp; &nbsp; &nbsp; if (!rv.equals(Pkcs11Constants.CKR_OK)) throw Pkcs11Exception.exceptionWithCode(rv);</p><p>дает ошибку CKR_TEMPLATE_INCONSISTENT (0xd1)<br />Какая может быть причина(ы)?</p><p>Вот сами функции set класса CK_ATTRIBUTE<br />&nbsp; &nbsp; public void set(@NonNull final NativeLong type, @NonNull final NativeLong value) {<br />&nbsp; &nbsp; &nbsp; &nbsp; this.type = type;<br />&nbsp; &nbsp; &nbsp; &nbsp; pValue = new NativeLongByReference(value).getPointer();<br />&nbsp; &nbsp; &nbsp; &nbsp; ulValueLen = new NativeLong(NativeLong.SIZE);<br />&nbsp; &nbsp; }</p><p>&nbsp; &nbsp; public void set(@NonNull final NativeLong type, @NonNull final boolean value) {<br />&nbsp; &nbsp; &nbsp; &nbsp; mBuffer = ByteBuffer.allocateDirect(1);<br />&nbsp; &nbsp; &nbsp; &nbsp; mBuffer.put(value? Pkcs11Constants.CK_TRUE : Pkcs11Constants.CK_FALSE);<br />&nbsp; &nbsp; &nbsp; &nbsp; pValue = Native.getDirectBufferPointer(mBuffer);<br />&nbsp; &nbsp; &nbsp; &nbsp; ulValueLen = new NativeLong(1);<br />&nbsp; &nbsp; }</p><p>&nbsp; &nbsp; public void set(@NonNull final NativeLong type, @NonNull final int value) {<br />&nbsp; &nbsp; &nbsp; &nbsp; this.type = type;<br />&nbsp; &nbsp; &nbsp; &nbsp; mBuffer = ByteBuffer.allocateDirect(4);<br />&nbsp; &nbsp; &nbsp; &nbsp; mBuffer.putInt(value);<br />&nbsp; &nbsp; &nbsp; &nbsp; pValue = Native.getDirectBufferPointer(mBuffer);<br />&nbsp; &nbsp; &nbsp; &nbsp; ulValueLen = new NativeLong(4);<br />&nbsp; &nbsp; }</p><p>&nbsp; &nbsp; public void set(@NonNull final NativeLong type, @NonNull final String value) {<br />&nbsp; &nbsp; &nbsp; &nbsp; this.type = type;<br />&nbsp; &nbsp; &nbsp; &nbsp; mBytes = value.getBytes();<br />&nbsp; &nbsp; &nbsp; &nbsp; mBuffer = ByteBuffer.allocateDirect(mBytes.length);<br />&nbsp; &nbsp; &nbsp; &nbsp; mBuffer.put(mBytes);<br />&nbsp; &nbsp; &nbsp; &nbsp; pValue = Native.getDirectBufferPointer(mBuffer);<br />&nbsp; &nbsp; &nbsp; &nbsp; ulValueLen = new NativeLong(mBytes.length);<br />&nbsp; &nbsp; }</p><p>&nbsp; &nbsp; public void set(@NonNull final NativeLong type, @NonNull final byte[] value) {<br />&nbsp; &nbsp; &nbsp; &nbsp; this.type = type;<br />&nbsp; &nbsp; &nbsp; &nbsp; mBuffer = ByteBuffer.allocateDirect(value.length);<br />&nbsp; &nbsp; &nbsp; &nbsp; mBuffer.put(value);<br />&nbsp; &nbsp; &nbsp; &nbsp; pValue = Native.getDirectBufferPointer(mBuffer);<br />&nbsp; &nbsp; &nbsp; &nbsp; ulValueLen = new NativeLong(value.length);<br />&nbsp; &nbsp; }</p>]]></content>
			<author>
				<name><![CDATA[Oleg Shishkin]]></name>
				<uri>https://forum.rutoken.ru/user/9901/</uri>
			</author>
			<updated>2015-10-24T12:04:19Z</updated>
			<id>https://forum.rutoken.ru/post/8949/#p8949</id>
		</entry>
</feed>
