title: X.509 certificate serial number to hex conversion
body: <p>I'm trying to get the serial number for an X.509 certificate using Pythons OpenSSL library.</p>
  
  <p>If I load my cert like this:</p>
  
  <pre><code> x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1, cert)
  </code></pre>
  
  <p>Then print the serial number like this:</p>
  
  <pre><code>print x509.get_serial_number()
  </code></pre>
  
  <p>It looks like this:</p>
  
  <pre><code>5.283978953499081e+37 
  </code></pre>
  
  <p>If I convert it to hex like this:</p>
  
  <pre><code>'{0:x}'.format(int(5.283978953499081e+37))
  </code></pre>
  
  <p>It returns this:</p>
  
  <pre><code>27c092c344a6c2000000000000000000
  </code></pre>
  
  <p>However, using OpenSSL from the command line to print the certificates serial number returns this.</p>
  
  <pre><code>27:c0:92:c3:44:a6:c2:35:29:8f:d9:a2:fb:16:f9:b7
  </code></pre>
  
  <p>Why is half of the serial number being converted to zeros? </p>