Flexiprovider椭圆曲线公钥从字节数组 [英] Flexiprovider elliptic curve public key from byte array
问题描述
我使用FlexiEC提供程序生成椭圆曲线公钥。然后我将该键转换为字节数组。之后,我想从这个字节数组获得这个公钥的实例。每当我这样做,我得到一个例外。
I'm using the FlexiEC provider to generate an elliptic curve public key. Then I convert the key into a byte array. After that I want to get an instance of this public key from this byte array. Whenever I do this I get an exception.
代码如下:
import java.security.KeyPair;
import java.security.KeyFactory;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Security;
import javax.crypto.Cipher;
import de.flexiprovider.common.ies.IESParameterSpec;
import de.flexiprovider.core.FlexiCoreProvider;
import de.flexiprovider.ec.FlexiECProvider;
import de.flexiprovider.ec.parameters.CurveParams;
import de.flexiprovider.ec.parameters.CurveRegistry.BrainpoolP160r1;
import de.flexiprovider.pki.X509EncodedKeySpec;
[...]
KeyPairGenerator kpg = KeyPairGenerator.getInstance("ECIES", "FlexiEC");
CurveParams ecParams = new BrainpoolP160r1();
kpg.initialize(ecParams, new SecureRandom());
KeyPair keyPair = kpg.generateKeyPair();
byte[] pubKey = keyPair.getPublic().getEncoded();
X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(pubKey);
KeyFactory keyFactory = KeyFactory.getInstance("ECIES", "FlexiEC");
PublicKey pk = keyFactory.generatePublic(pubKeySpec);
例外是:
Exception in thread "main" de.flexiprovider.api.exceptions.InvalidKeySpecException: java.lang.RuntimeException: java.security.InvalidAlgorithmParameterException: Caught IOException("Unknown named curve: 1.3.36.3.3.2.8.1.1.1")
at de.flexiprovider.ec.keys.ECKeyFactory.generatePublic(ECKeyFactory.java:205)
at de.flexiprovider.api.keys.KeyFactory.engineGeneratePublic(KeyFactory.java:39)
at java.security.KeyFactory.generatePublic(KeyFactory.java:328)
at com.test.App.test(App.java:68)
at com.test.App.main(App.java:76)
如何从字节数组中正确恢复密钥? p>
How can I recover the key correctly from the byte array?
推荐答案
我有一些ECIES,FlexiEC代码可供您参考。这是链接:
I have some "ECIES", "FlexiEC" code which may be of reference for you. Here is the link:
BadPaddingException: invalid ciphertext
如果这有帮助,那么owlstead会回答我的问题,让我完成实施。
If this helps, the credit goes to owlstead who answered the question for me which enabled me to complete the implementation.
这篇关于Flexiprovider椭圆曲线公钥从字节数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!