如何解决在ECDSA的曲线secp256k1中添加两个点的问题?

时间:2019-01-05 22:34:03

标签: android ecdsa

我收到此错误: ava.lang.ClassCastException:org.bouncycastle.math.ec.ECFieldElement $ Fp无法转换为org.bouncycastle.math.ec.custom.sec.SecP256K1FieldElement

一次尝试在android中将公用密钥读取为字符串,该字符串是从.pem文件中以

检索的

----- BEGIN公钥----- \ n MIH1MIGuBgcqhkjOPQIBMIGiAgEBMCwGByqGSM49AQECIQD ///////////////// ///////////////// + /// 8LzAGBAEABAEHBEEEeb5mfvncu6xVoGKVzocLBwKb / NstzijZWfKBWxb4F5hIOtp3JqPEZV2k + / wOEQio / Re0SKaFVBmcR9CP + xDUuAIh AP /////////////////// 66rtzmr0igO7 / SXozQNkFBAgEBA0IABK5F1KgwnBG3 jVLqtqJ9 + uesDOzP00s88bgGyYQen86xLn1iUJxy / qPPmn9WZyfQ + b27UaHNAa09 83BuGKHERAE = \ n ----- END公钥-----

此密钥来自secp256k1类型

这是读取公共密钥的代码部分:

       Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME);

       Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());                                                
        Reader rdr = new StringReader (keys[seletedTFE]);
        Object parsed = new     org.bouncycastle.openssl.PEMParser(rdr).readObject();
        ECPublicKey key = (ECPublicKey) new    org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter().getPublicKey((Subje.ctPublicKeyInfo) parsed);

         ECPoint P = key.getQ();

和由于这一点而导致的错误:将C1与C2相加,并说类型为ECpointfp的C2而类型为ECElementFieldsecp256k1的C2

     ECPoint C1;
     ECPoint C2;
     ECPoint C3;
     C2 = P.multiply(beta);
     C3 = C1.add(C2)   ;                    

并且此代码可用于prime256v1和secp256r1,但是我需要使用secp256k1,那么如何解决此问题?

0 个答案:

没有答案