DefaultSubjectKeyIdentifierWriter implements SubjectKeyIdentifierWriter { @Override public byte[] getSubjectKeyIdentifier(KeyPair clientKeyPair, Set<X509ExtensionWrapper> extensions) throws IOException { try { MessageDigest d = MessageDigest.getInstance("SHA-1"); byte[] encodedKey = clientKeyPair.getPublic().getEncoded(); DerInputStream s = new DerValue(encodedKey).toDerInputStream(); s.skipSequence(0); BitArray b = s.getUnalignedBitString(); byte[] digest = d.digest(b.toByteArray()); KeyIdentifier ki = new KeyIdentifier(digest); return ASN1Util.encode(new OCTET_STRING(ki.getIdentifier())); } catch (NoSuchAlgorithmException e) { throw new IOException("Could not create KeyIdentifier", e); } }  @Override byte[] getSubjectKeyIdentifier(KeyPair clientKeyPair, Set<X509ExtensionWrapper> extensions);  }
@Test public void getSubjectKeyIdentifier() throws Exception { DefaultSubjectKeyIdentifierWriter writer = new DefaultSubjectKeyIdentifierWriter(); byte[] actual = writer.getSubjectKeyIdentifier(keyPair, null); byte[] expected = new JcaX509ExtensionUtils() .createSubjectKeyIdentifier(keyPair.getPublic()) .getEncoded(); assertArrayEquals(expected, actual); }