0

我正在使用 FlexiEC 提供程序来生成椭圆曲线公钥。然后我将密钥转换为字节数组。之后,我想从这个字节数组中获取这个公钥的一个实例。每当我这样做时,我都会遇到异常。

代码如下:

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)

如何从字节数组中正确恢复密钥?

4

1 回答 1

0

我有一些“ECIES”、“FlexiEC”代码可能对你有参考意义。链接在这里:

BadPaddingException:无效的密文

如果这有帮助,那归功于 owlstead,他为我回答了这个问题,这使我能够完成实施。

于 2013-11-27T08:35:30.073 回答