我有一個(gè)使用 BouncyCastle 作為安全提供程序的應(yīng)用程序,但我想切換到另一個(gè)直接使用 OpenSSL (Conscrypt) 的應(yīng)用程序。我遇到的問題是我使用的是 BouncyCastle 提供的 KeyGenerator 中的 ECDH“密鑰”,但我的其他庫(kù)中沒有類似的 KeyGenerator。為了比較兩者,我將使用兩種方法和以下輸入來解碼這些點(diǎn) -添加換行符以提高可讀性BADX_GAXp03z_5p05O1-op61KJAl4j9U2sBnAnJ4p_6GSAIyFGU3lMoC4aIXw_2qlTnplykArgjvwCWw-2g6L44使用 BouncyCastle 方法-public org.bouncycastle.jce.interfaces.ECPublicKey loadECPublicKeyBC(String encodedPublicKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException, IOException { Base64.Decoder base64Decoder = Base64.getUrlDecoder(); byte[] decodedPublicKey = base64Decoder.decode(encodedPublicKey); KeyFactory keyFactory = KeyFactory.getInstance("ECDH", "BC"); ECParameterSpec ecParameterSpec = ECUtil.getECParameterSpec(openSSLProvider, "prime256v1"); ECPoint ecPoint = ECUtil.decodePoint(decodedPublicKey, ecParameterSpec.getCurve()); ECPublicKeySpec pubSpec = new ECPublicKeySpec(ecPoint, ecParameterSpec); org.bouncycastle.jce.interfaces.ECPublicKey ecPublicKey = (org.bouncycastle.jce.interfaces.ECPublicKey)keyFactory.generatePublic(pubSpec); return ecPublicKey;}返回getAlgorithm的是EC。返回getFormat的是X.509。getEncoded這個(gè)的價(jià)值是——[48,-126,1,51,48,-127,-20,6,7,42,-122,72,-50,61,2,1,48,-127,-32,2,1,1,48,44,6,7,42,-122,72,-50,61,1,1,2,33,0,-1,-1,-1,-1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,48,68,4,32,-1,-1,-1,-1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-4,4,32,90,-58,53,-40,-86,58,-109,-25,-77,-21,-67,85,118,-104,-122,-68,101,29,6,-80,-52,83,-80,-10,59,-50,60,62,39,-46,96,75,4,65,4,107,23,-47,-14,-31,44,66,71,-8,-68,-26,-27,99,-92,64,-14,119,3,125,-127,45,-21,51,-96,-12,-95,57,69,-40,-104,-62,-106,79,-29,66,-30,-2,26,127,-101,
查看完整描述