我正在使用Java
withBouncy Castle
将服务器端转换string_1
为ECDH
PublicKey
,然后将其转换PublicKey
为string_2
以检查代码的正确性,但是string_1
andstring_2
不同,我不知道哪里出了问题。
String key ="BJNiB1+k2n2hiYZccfwGE87mbo5+29l+PFfKzO72tvDmXCAT4QtxqqgX2vUi5go1+MpjJCFyBmIfv5jcsOo9fo3cd/v2jwZAyh2IHh7NHWkA6PFip6el2rNfvyNCd5eN6Q==";
System.out.println("server key:" + key);
byte[] keyBytes = Base64.decodeBase64(key.getBytes("utf-8"));
ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec("secp384r1");
KeyFactory kf = KeyFactory.getInstance("ECDH", new BouncyCastleProvider());
ECNamedCurveSpec params = new ECNamedCurveSpec("secp384r1", spec.getCurve(), spec.getG(), spec.getN());
ECPoint point = ECPointUtil.decodePoint(params.getCurve(), keyBytes);
ECPublicKeySpec pubKeySpec1 = new ECPublicKeySpec(point, params);
PublicKey pk = kf.generatePublic(pubKeySpec1);
System.out.println("convert Key*: " + Base64.encodeBase64String(pk.getEncoded()));
server key和convert key不一样,找不到原因,求帮助!
server key:BJNiB1+k2n2hiYZccfwGE87mbo5+29l+PFfKzO72tvDmXCAT4QtxqqgX2vUi5go1+MpjJCFyBmIfv5jcsOo9fo3cd/v2jwZAyh2IHh7NHWkA6PFip6el2rNfvyNCd5eN6Q==
convert Key*: MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEk2IHX6TafaGJhlxx/AYTzuZujn7b2X48V8rM7va28OZcIBPhC3GqqBfa9SLmCjX4ymMkIXIGYh+/mNyw6j1+jdx3+/aPBkDKHYgeHs0daQDo8WKnp6Xas1+/I0J3l43p