private String gainPrincipalFromAlias ( String alias , KeyStore keystore ) throws Exception { if ( keystore == null ) { return null ; } if ( ! keystore . containsAlias ( alias ) ) { return null ; } Certificate certificate = keystore . getCertificate ( alias ) ; if ( certificate == null || ! ( certificate instanceof X509Certificate ) ) { return null ; } X509Certificate x509Certificate = ( X509Certificate ) certificate ; X500Principal principal = new X500Principal ( x509Certificate . getSubjectX500Principal ( ) . toString ( ) ) ; return principal . getName ( ) ; }
Private method for gaining X500Principal from keystore according its alias .