Last active
August 29, 2015 14:17
-
-
Save gregorej/2a3b7c1b417d59c140af to your computer and use it in GitHub Desktop.
Get public key from X509 certificate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.FileInputStream; | |
import java.io.FileNotFoundException; | |
import java.security.PublicKey; | |
import java.security.cert.CertificateException; | |
import java.security.cert.CertificateFactory; | |
import java.security.cert.X509Certificate; | |
import org.junit.Test; | |
public class CertificatesTest { | |
@Test | |
public void getPublickeyFromCertificate() throws CertificateException, FileNotFoundException { | |
final String certPath = "from_rest.cert"; | |
FileInputStream fin = new FileInputStream(certPath); | |
CertificateFactory f = CertificateFactory.getInstance("X.509"); | |
X509Certificate certificate = (X509Certificate)f.generateCertificate(fin); | |
PublicKey pk = certificate.getPublicKey(); | |
System.out.println(pk.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment