@Test void testES256KPublicKey() throws AlgorithmException { String keyId = "es256k"; Algorithm algorithm = AlgorithmProvider.create(AlgorithmProvider.Type.ES256K); KeyProvider keyProvider = algorithm.generateKeyProvider(keyId); System.out.println(keyProvider.getPublicKey()); byte[] pub = ((ECPublicKey) keyProvider.getPublicKey()).getQ().getEncoded(false); ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec("secp256k1"); ECDomainParameters domain = new ECDomainParameters(spec.getCurve(), spec.getG(), spec.getN()); ECParameterSpec ecparameterSpec = new ECParameterSpec(spec.getCurve(), spec.getG(), spec.getN()); try { KeyFactory fact = KeyFactory.getInstance("EC", "BC"); PublicKey publicKey = fact.generatePublic(new ECPublicKeySpec(spec.getCurve().decodePoint(pub), ecparameterSpec)); System.out.println(publicKey); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (NoSuchProviderException e) { e.printStackTrace(); } catch (InvalidKeySpecException e) { e.printStackTrace(); } }
public PublicKey getPublicKey() { return publicKey; }
KeyProvider { public PublicKey getPublicKey() { return publicKey; } }
KeyProvider { public PublicKey getPublicKey() { return publicKey; } private  KeyProvider(Builder builder); }
KeyProvider { public PublicKey getPublicKey() { return publicKey; } private  KeyProvider(Builder builder); String getKeyId(); AlgorithmProvider.Type getType(); PublicKey getPublicKey(); PrivateKey getPrivateKey(); Builder newBuilder(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); }
KeyProvider { public PublicKey getPublicKey() { return publicKey; } private  KeyProvider(Builder builder); String getKeyId(); AlgorithmProvider.Type getType(); PublicKey getPublicKey(); PrivateKey getPrivateKey(); Builder newBuilder(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode();  }