Skip to main content
replaced https://tools.ietf.org/html/rfc with https://www.rfc-editor.org/rfc/rfc
Source Link

TLDR: The leading 0x00 is a SIGN BYTE that openssl adds for the printout only. It is NOT encoded in the certificate itself. And I guess you can cut of the leading byte (one of 0x02, 0x03 or 0x040x02, 0x03 or 0x04) of the pubkey because it just stores info on whether compressed or noncompressed encoding is used.

According to RFC5915RFC5915 (I think) an EC key is an UNSIGNED integer.

TLDR: The leading 0x00 is a SIGN BYTE that openssl adds for the printout only. It is NOT encoded in the certificate itself. And I guess you can cut of the leading byte (one of 0x02, 0x03 or 0x04) of the pubkey because it just stores info on whether compressed or noncompressed encoding is used.

According to RFC5915 (I think) an EC key is an UNSIGNED integer.

TLDR: The leading 0x00 is a SIGN BYTE that openssl adds for the printout only. It is NOT encoded in the certificate itself. And I guess you can cut of the leading byte (one of 0x02, 0x03 or 0x04) of the pubkey because it just stores info on whether compressed or noncompressed encoding is used.

According to RFC5915 (I think) an EC key is an UNSIGNED integer.

+ asn1editor screenshots
Source Link
StackzOfZtuff
  • 18.2k
  • 1
  • 54
  • 86

ASN.1 Editor "leading-nullbyte.pem": no 0x00actual null byte

As an afterthought: Here's also an actual hexdump of the DER contents. And again: no actual 0x00 in the file. ASN.1 Editor: no 0x00asn1editor.leading-nullbyte.pem.png

ASN.1 Editor no-leading-nullbyte.pem

asn1editor.no-leading-nullbyte.pem.png

ASN.1 Editor "leading-nullbyte.pem": no 0x00

As an afterthought: Here's also an actual hexdump of the DER contents. And again: no actual 0x00 in the file. ASN.1 Editor: no 0x00

ASN.1 Editor "leading-nullbyte.pem": no actual null byte

As an afterthought: Here's also an actual hexdump of the DER contents. And again: no actual 0x00 in the file. asn1editor.leading-nullbyte.pem.png

ASN.1 Editor no-leading-nullbyte.pem

asn1editor.no-leading-nullbyte.pem.png

+screenshot ASN.1 editor
Source Link
StackzOfZtuff
  • 18.2k
  • 1
  • 54
  • 86

#Sample key with leading nullbyte Here's an example of a random key I generated:

Sample key with leading nullbyte

Here's an example of a random key I generated:

ec printout leading-nullbyte.pem

##ec printout leading-nullbyte.pem ThisThis key is shown with the "00:" prefix for the private key.

asn1parse leading-nullbyte.pem

##asn1parse leading-nullbyte.pem ...however when actually looking inside the ASN1 encoding there is no 00: prefix. It just starts with df: right away. And also: length is given as 32 (l= 32). Not 33.

ASN.1 Editor "leading-nullbyte.pem": no 0x00

#Sample key WITHOUT leading nullbyte Here's another random key I generated. It does NOT haveAs an afterthought: Here's also an actual hexdump of the DER contents. And again: no actual 0x00 prefix when usingin the openssl ec pretty printerfile. ASN.1 Editor: no 0x00

Sample key WITHOUT leading nullbyte

Here's another random key I generated. It does NOT have the 0x00 prefix when using the openssl ec pretty printer.

##ec printout no-leading-nullbyte.pem $ openssl ec -noout -text -in no-leading-nullbyte.pem read EC key Private-Key: (256 bit) priv: 01:9c:16:83:df:a9:f1:59:e5:30:ef:ef:56:41:04: 27:2d:6a:98:95:2b:06:62:90:4f:07:7c:a7:fa:d5: 5d:43 pub: 04:34:f8:ca:bf:db:e8:6c:99:f3:d4:54:a5:4a:ee: 5c:34:fc:8f:c0:2b:dc:b0:c9:88:af:91:c7:f7:60: be:99:97:55:b5:a9:c7:c2:54:e6:db:d2:30:38:4e: 65:48:4f:0a:33:2c:08:26:cf:29:2c:2b:d7:ef:d9: 09:85:9f:ee:a6 ASN1 OID: prime256v1 NIST CURVE: P-256

ec printout no-leading-nullbyte.pem

$ openssl ec -noout -text -in no-leading-nullbyte.pem
read EC key
Private-Key: (256 bit)
priv:
    01:9c:16:83:df:a9:f1:59:e5:30:ef:ef:56:41:04:
    27:2d:6a:98:95:2b:06:62:90:4f:07:7c:a7:fa:d5:
    5d:43
pub:
    04:34:f8:ca:bf:db:e8:6c:99:f3:d4:54:a5:4a:ee:
    5c:34:fc:8f:c0:2b:dc:b0:c9:88:af:91:c7:f7:60:
    be:99:97:55:b5:a9:c7:c2:54:e6:db:d2:30:38:4e:
    65:48:4f:0a:33:2c:08:26:cf:29:2c:2b:d7:ef:d9:
    09:85:9f:ee:a6
ASN1 OID: prime256v1
NIST CURVE: P-256

asn1parse no-leading-nullbyte.pem

#asn1parse no-leading-nullbyte.pem HereHere again length is given as 32:

Extra: How do I know that the 0x00 is a sign byte?

#Extra: How do I know that the 0x00 is a sign byte? ... by experimentation:

#Sample key with leading nullbyte Here's an example of a random key I generated:

##ec printout leading-nullbyte.pem This key is shown with the "00:" prefix for the private key.

##asn1parse leading-nullbyte.pem ...however when actually looking inside the ASN1 encoding there is no 00: prefix. It just starts with df: right away. And also: length is given as 32 (l= 32). Not 33.

#Sample key WITHOUT leading nullbyte Here's another random key I generated. It does NOT have the 0x00 prefix when using the openssl ec pretty printer.

##ec printout no-leading-nullbyte.pem $ openssl ec -noout -text -in no-leading-nullbyte.pem read EC key Private-Key: (256 bit) priv: 01:9c:16:83:df:a9:f1:59:e5:30:ef:ef:56:41:04: 27:2d:6a:98:95:2b:06:62:90:4f:07:7c:a7:fa:d5: 5d:43 pub: 04:34:f8:ca:bf:db:e8:6c:99:f3:d4:54:a5:4a:ee: 5c:34:fc:8f:c0:2b:dc:b0:c9:88:af:91:c7:f7:60: be:99:97:55:b5:a9:c7:c2:54:e6:db:d2:30:38:4e: 65:48:4f:0a:33:2c:08:26:cf:29:2c:2b:d7:ef:d9: 09:85:9f:ee:a6 ASN1 OID: prime256v1 NIST CURVE: P-256

#asn1parse no-leading-nullbyte.pem Here again length is given as 32:

#Extra: How do I know that the 0x00 is a sign byte? ... by experimentation:

Sample key with leading nullbyte

Here's an example of a random key I generated:

ec printout leading-nullbyte.pem

This key is shown with the "00:" prefix for the private key.

asn1parse leading-nullbyte.pem

...however when actually looking inside the ASN1 encoding there is no 00: prefix. It just starts with df: right away. And also: length is given as 32 (l= 32). Not 33.

ASN.1 Editor "leading-nullbyte.pem": no 0x00

As an afterthought: Here's also an actual hexdump of the DER contents. And again: no actual 0x00 in the file. ASN.1 Editor: no 0x00

Sample key WITHOUT leading nullbyte

Here's another random key I generated. It does NOT have the 0x00 prefix when using the openssl ec pretty printer.

ec printout no-leading-nullbyte.pem

$ openssl ec -noout -text -in no-leading-nullbyte.pem
read EC key
Private-Key: (256 bit)
priv:
    01:9c:16:83:df:a9:f1:59:e5:30:ef:ef:56:41:04:
    27:2d:6a:98:95:2b:06:62:90:4f:07:7c:a7:fa:d5:
    5d:43
pub:
    04:34:f8:ca:bf:db:e8:6c:99:f3:d4:54:a5:4a:ee:
    5c:34:fc:8f:c0:2b:dc:b0:c9:88:af:91:c7:f7:60:
    be:99:97:55:b5:a9:c7:c2:54:e6:db:d2:30:38:4e:
    65:48:4f:0a:33:2c:08:26:cf:29:2c:2b:d7:ef:d9:
    09:85:9f:ee:a6
ASN1 OID: prime256v1
NIST CURVE: P-256

asn1parse no-leading-nullbyte.pem

Here again length is given as 32:

Extra: How do I know that the 0x00 is a sign byte?

... by experimentation:

added 278 characters in body
Source Link
StackzOfZtuff
  • 18.2k
  • 1
  • 54
  • 86
Loading
added 278 characters in body
Source Link
StackzOfZtuff
  • 18.2k
  • 1
  • 54
  • 86
Loading
added 2546 characters in body
Source Link
StackzOfZtuff
  • 18.2k
  • 1
  • 54
  • 86
Loading
added 289 characters in body
Source Link
StackzOfZtuff
  • 18.2k
  • 1
  • 54
  • 86
Loading
Source Link
StackzOfZtuff
  • 18.2k
  • 1
  • 54
  • 86
Loading