private String generateDigest ( String algorithmName , X509Certificate cert ) { try { MessageDigest md = MessageDigest . getInstance ( algorithmName ) ; md . update ( cert . getEncoded ( ) ) ; byte data [ ] = md . digest ( ) ; StringBuilder buffer = new StringBuilder ( 3 * data . length ) ; int i = 0 ; buffer . append ( HEX_CHARS [ ( data [ i ] >> 4 ) & 0xF ] ) ; buffer . append ( HEX_CHARS [ ( data [ i ] % 16 ) & 0xF ] ) ; for ( ++ i ; i < data . length ; i ++ ) { buffer . append ( ' ' ) ; buffer . append ( HEX_CHARS [ ( data [ i ] >> 4 ) & 0xF ] ) ; buffer . append ( HEX_CHARS [ ( data [ i ] % 16 ) & 0xF ] ) ; } return buffer . toString ( ) ; } catch ( NoClassDefFoundError e ) { return getMessage ( "sslTrust.genDigestError" , algorithmName , e . getMessage ( ) ) ; } catch ( Exception e ) { return getMessage ( "sslTrust.genDigestError" , algorithmName , e . getMessage ( ) ) ; } }
This method is used to create a SHA - 1 or MD5 digest on an X509Certificate as the fingerprint .