2013-09-27 102 views
0

我正在使用FlexiEC提供程序來生成橢圓曲線公鑰。然後我將密鑰轉換成一個字節數組。之後,我想從這個字節數組中獲得這個公鑰的一個實例。每當我這樣做,我得到一個例外。來自字節數組的Flexiprovider橢圓曲線公用密鑰

的代碼如下:

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) 

如何從字節數組正確恢復的關鍵?

回答

0

我有一些「ECIES」,「FlexiEC」代碼,可能是你的參考。這裏是鏈接:

BadPaddingException: invalid ciphertext

如果這會有所幫助,要歸功於owlstead誰回答使我能夠完成實現了我的問題。