Note that there are some explanatory texts on larger screens.

plurals
  1. POget X509Certificate serial number
    primarykey
    data
    text
    <p>I need to get serial number of x509 certificate. The result of usage "certificate.getSerialNumber()" differs from the expected. As I see X509 certificate file specs, it should go in following format:</p> <pre><code> Certificate ::= SEQUENCE { tbsCertificate TBSCertificate, signatureAlgorithm AlgorithmIdentifier, signatureValue BIT STRING } TBSCertificate ::= SEQUENCE { version [0] EXPLICIT Version DEFAULT v1, serialNumber CertificateSerialNumber, signature AlgorithmIdentifier, issuer Name, validity Validity, subject Name, subjectPublicKeyInfo SubjectPublicKeyInfo, issuerUniqueID [1] IMPLICIT UniqueIdentifier OPTIONAL, -- If present, version shall be v2 or v3 subjectUniqueID [2] IMPLICIT UniqueIdentifier OPTIONAL, -- If present, version shall be v2 or v3 extensions [3] EXPLICIT Extensions OPTIONAL -- If present, version shall be v3 } </code></pre> <p>And I couldn't find in the begining of the file the value that is provided by certificate.getSerialNumber() method. </p> <p>And related question: When trying to display the serial with openssl it takes right value from file but adds '3' after each number.</p> <p>So my question is: How can I get the stored serial value? And where to read why and how openssl and java modifies this data.</p> <p><strong>OPENSSL</strong></p> <p>Run with:</p> <pre><code>openssl x509 -serial -noout -inform DER -in mycert.cer </code></pre> <p>Result:</p> <pre><code>serial=3030303031303030303030313030373439323639 </code></pre> <p><strong>JAVA</strong></p> <p>Code:</p> <pre><code>InputStream in = new FileInputStream("mycert.cer"); BouncyCastleProvider provider = new BouncyCastleProvider(); CertificateFactory certificateFactory = CertificateFactory.getInstance("X509", provider); X509Certificate certificate = (X509Certificate) certificateFactory.generateCertificate(in); BigInteger serialNum = certificate.getSerialNumber(); System.out.println(serialNum); </code></pre> <p>Output:</p> <pre><code>275106190557734483187066766755592068430195471929 </code></pre> <p><strong>FILE</strong></p> <p>And viewing the file, I see:</p> <pre><code>0...0..r.......000010000001007492690 . *.H.. .. </code></pre> <p>which seems to be the serial, provided by openssl but openssl mix it with '3'(after each number).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload