Skip to content

Instantly share code, notes, and snippets.

@rsatrio
Created May 7, 2022 22:55
Show Gist options
  • Save rsatrio/81f243924432947e9dd2239f8e6a3408 to your computer and use it in GitHub Desktop.
Save rsatrio/81f243924432947e9dd2239f8e6a3408 to your computer and use it in GitHub Desktop.
Getting Public Key in CMS
//Getting PublicKey
Collection<X509CertificateHolder> matches = signedData.getCertificates().getMatches(signerInfo.getSID());
byte[] pubByte=matches.iterator().next().getSubjectPublicKeyInfo().getEncoded();
X509EncodedKeySpec keySpec=new X509EncodedKeySpec(pubByte);
KeyFactory kf = KeyFactory.getInstance("RSA");
PublicKey pubKey=kf.generatePublic(keySpec);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment