Missing leading zeroes while retrieving serial number of a x509 cert

前端 未结 1 1190
走了就别回头了
走了就别回头了 2021-01-15 22:11

I\'m trying to get serial number from a X.509 Cert.. When i compare the Serial number generated by my code with the actual serial number(on windows), leading zeroes of the

相关标签:
1条回答
  • 2021-01-15 22:46

    BigInteger has a toByteArray() method that re-adds the leading 00s:

    byte[] serialNumBA = certificate.getSerialNumber().toByteArray()
    

    Now you have several ways to convert the byte array to a hex string:

    How to convert a byte array to a hex string in Java?

    For example with Apache commons codec:

    String serialNum = Hex.encodeHexString(serialNumBA);
    
    0 讨论(0)
提交回复
热议问题