Skip to main content
Polish
Source Link
fgrieu
  • 145.5k
  • 12
  • 319
  • 611

The question is for the standard 256-bit Elliptic Curve secp256k1. It wants the key in the format described in sec1v2, section 2.3.3 Elliptic-Curve-Point-to-Octet-String Conversion, with point compression, that is per 2.1/2.2.1/2.3/2.4

The desired compressed public key starts with byte 02 or 03 (with the same parity as the $Y$ coordinate), followed by the $X$ coordinate in big-endian notation over 32 bytes. Further conversion to hexadecimal makes that a 66-character string.

To decode the DER-encoded public key SubjectPublicKeyInfo or X.509 certificate, one can use this online tool, which accepts hex and base64. As this comment points out, it will normally containshow the point(point representative of) the public key either

  • in a bitstring which data is in the uncompressed format of 65 bytes (520 bits), the first of which is 04, followed by the $X$ coordinate and the $Y$ coordinate in big-endian notation each over 32 bytes. In order to convert to compressed format, we can replace the initial 04 with 02 or 03 (determined so that it has the same parity as the last byte), and remove the last 32 bytes.
  • in a bitstring which data already is in the desired compressed format of 33 bytes (264 bits), the first of which is 02or 03.

Note: In other conversion contexts I have met $X$ and $Y$ coordinates encoded as ASN.1 integer in the public key. Facing this, the textbook solution is to use an ASN.1 library. When doing without, be careful that the ASN.1 encoding of integers has variable length, so that it may be needed to remove one leading 00 (≲50% of the cases), or add one 00 (<0.4% of the cases) or even more (<0.002%).

Note: One might want to check that $X$, and $Y$ if available, form a valid secp256k1 public key, that is: for $p=2^{256}-2^{32}−977$ (the prime field order) it holds

  • $0<X<p$
  • if $Y$ is available, that $0<Y<p$ and $X^3+7-Y^2\bmod p=0$
  • otherwise, that $(X^3+7)^{(p-1)/2}\bmod p=1$

The question is for the standard 256-bit Elliptic Curve secp256k1. It wants the key in the format described in sec1v2, section 2.3.3 Elliptic-Curve-Point-to-Octet-String Conversion, with point compression, that is per 2.1/2.2.1/2.3/2.4

The desired compressed public key starts with byte 02 or 03 (with the same parity as the $Y$ coordinate), followed by the $X$ coordinate in big-endian notation over 32 bytes. Further conversion to hexadecimal makes that a 66-character string.

To decode the DER-encoded public key SubjectPublicKeyInfo or X.509 certificate, one can use this online tool, which accepts hex and base64. As this comment points out, it will normally contain the point representative of the public key either

  • in a bitstring which data is in the uncompressed format of 65 bytes (520 bits), the first of which is 04, followed by the $X$ coordinate and the $Y$ coordinate in big-endian notation each over 32 bytes. In order to convert to compressed format, we can replace the initial 04 with 02 or 03 (determined so that it has the same parity as the last byte), and remove the last 32 bytes.
  • in a bitstring which data already is in the desired compressed format of 33 bytes (264 bits), the first of which is 02or 03.

Note: In other conversion contexts I have met $X$ and $Y$ coordinates encoded as ASN.1 integer in the public key. Facing this, the textbook solution is to use an ASN.1 library. When doing without, be careful that the ASN.1 encoding of integers has variable length, so that it may be needed to remove one leading 00 (≲50% of the cases), or add one 00 (<0.4% of the cases) or even more (<0.002%).

Note: One might want to check that $X$, and $Y$ if available, form a valid secp256k1 public key, that is: for $p=2^{256}-2^{32}−977$ (the prime field order) it holds

  • $0<X<p$
  • if $Y$ is available, that $0<Y<p$ and $X^3+7-Y^2\bmod p=0$
  • otherwise, that $(X^3+7)^{(p-1)/2}\bmod p=1$

The question is for the standard 256-bit Elliptic Curve secp256k1. It wants the key in the format described in sec1v2, section 2.3.3 Elliptic-Curve-Point-to-Octet-String Conversion, with point compression, that is per 2.1/2.2.1/2.3/2.4

The desired compressed public key starts with byte 02 or 03 (with the same parity as the $Y$ coordinate), followed by the $X$ coordinate in big-endian notation over 32 bytes. Further conversion to hexadecimal makes that a 66-character string.

To decode the DER-encoded public key SubjectPublicKeyInfo or X.509 certificate, one can use this online tool, which accepts hex and base64. As this comment points out, it will normally show the (point representative of) the public key either

  • in a bitstring which data is in the uncompressed format of 65 bytes (520 bits), the first of which is 04, followed by the $X$ coordinate and the $Y$ coordinate in big-endian notation each over 32 bytes. In order to convert to compressed format, we can replace the initial 04 with 02 or 03 (determined so that it has the same parity as the last byte), and remove the last 32 bytes.
  • in a bitstring which data already is in the desired compressed format of 33 bytes (264 bits), the first of which is 02or 03.

Note: In other conversion contexts I have met $X$ and $Y$ coordinates encoded as ASN.1 integer in the public key. Facing this, the textbook solution is to use an ASN.1 library. When doing without, be careful that the ASN.1 encoding of integers has variable length, so that it may be needed to remove one leading 00 (≲50% of the cases), or add one 00 (<0.4% of the cases) or even more (<0.002%).

Note: One might want to check that $X$, and $Y$ if available, form a valid secp256k1 public key, that is: for $p=2^{256}-2^{32}−977$ (the prime field order) it holds

  • $0<X<p$
  • if $Y$ is available, that $0<Y<p$ and $X^3+7-Y^2\bmod p=0$
  • otherwise, that $(X^3+7)^{(p-1)/2}\bmod p=1$
Polish
Source Link
fgrieu
  • 145.5k
  • 12
  • 319
  • 611

The question is for the standard 256-bit Elliptic Curve secp256k1. It wants the key in the format described in sec1v2, section 2.3.3 Elliptic-Curve-Point-to-Octet-String Conversion, with point compression, that is per 2.1/2.2.1/2.3/2.4

The desired compressed public key starts with byte 02 or 03 (with the same parity as the $Y$ coordinate), followed by the $X$ coordinate in big-endian notation over 32 bytes. Further conversion to hexadecimal makes that a 66-character string.

To decode the DER-encoded public key SubjectPublicKeyInfo or X.509 certificate, one can use this online tool, which accepts hex and base64. As this comment points out, it will normally contain the point representative of the public key either

  • in a bitstring which data already is in the desired compressed format of 33 bytes (264 bits).
  • in a bitstring which data is in the uncompressed format of 65 bytes (520 bits), the first of which is 04, followed by the $X$ coordinate and the $Y$ coordinate in big-endian notation each over 32 bytes. In order to convert to compressed format, we can replace the initial 04 with 02 or 03 (withdetermined so that it has the same parity as the last byte), and remove the last 32 bytes.
  • in a bitstring which data already is in the desired compressed format of 33 bytes (264 bits), the first of which is 02or 03.

Note: In other conversion contexts I have met $X$ and $Y$ coordinates encoded as ASN.1 integer in the public key. Facing this, the textbook solution is to use an ASN.1 library. When doing without, be careful that the ASN.1 encoding of integers has variable length, so that it may be needed to remove one leading 00 (≲50% of the cases), or add one 00 (<0.4% of the cases) or even more (<0.002%).

Note: One might want to check that $X$, and $Y$ if available, form a valid secp256k1 public key, that is: for $p=2^{256}-2^{32}−977$ (the prime field order) it holds

  • $0<X<p$
  • if $Y$ is available, that
    • $0<Y<p$
    • $X^3+7-Y^2\bmod p=0$
    $0<Y<p$ and $X^3+7-Y^2\bmod p=0$
  • otherwise, that $(X^3+7)^{(p-1)/2}\bmod p=1$

The question is for the standard 256-bit Elliptic Curve secp256k1. It wants the key in the format described in sec1v2, section 2.3.3 Elliptic-Curve-Point-to-Octet-String Conversion, with point compression, that is per 2.1/2.2.1/2.3/2.4

The desired compressed public key starts with byte 02 or 03 (with the same parity as the $Y$ coordinate), followed by the $X$ coordinate in big-endian notation over 32 bytes. Further conversion to hexadecimal makes that a 66-character string.

To decode the DER-encoded public key SubjectPublicKeyInfo or X.509 certificate, one can use this online tool, which accepts hex and base64. As this comment points out, it will normally contain the point representative of the public key either

  • in a bitstring which data already is in the desired compressed format of 33 bytes (264 bits).
  • in a bitstring which data is in the uncompressed format of 65 bytes (520 bits), the first of which is 04, followed by the $X$ coordinate and the $Y$ coordinate in big-endian notation each over 32 bytes. In order to convert to compressed format, we can replace the initial 04 with 02 or 03 (with the same parity as the last byte), and remove the last 32 bytes.

Note: In other conversion contexts I have met $X$ and $Y$ coordinates encoded as ASN.1 integer in the public key. Facing this, the textbook solution is to use an ASN.1 library. When doing without, be careful that the ASN.1 encoding of integers has variable length, so that it may be needed to remove one leading 00 (≲50% of the cases), or add one 00 (<0.4% of the cases) or even more (<0.002%).

Note: One might want to check that $X$, and $Y$ if available, form a valid secp256k1 public key, that is: for $p=2^{256}-2^{32}−977$ (the prime field order) it holds

  • $0<X<p$
  • if $Y$ is available, that
    • $0<Y<p$
    • $X^3+7-Y^2\bmod p=0$
  • otherwise, that $(X^3+7)^{(p-1)/2}\bmod p=1$

The question is for the standard 256-bit Elliptic Curve secp256k1. It wants the key in the format described in sec1v2, section 2.3.3 Elliptic-Curve-Point-to-Octet-String Conversion, with point compression, that is per 2.1/2.2.1/2.3/2.4

The desired compressed public key starts with byte 02 or 03 (with the same parity as the $Y$ coordinate), followed by the $X$ coordinate in big-endian notation over 32 bytes. Further conversion to hexadecimal makes that a 66-character string.

To decode the DER-encoded public key SubjectPublicKeyInfo or X.509 certificate, one can use this online tool, which accepts hex and base64. As this comment points out, it will normally contain the point representative of the public key either

  • in a bitstring which data is in the uncompressed format of 65 bytes (520 bits), the first of which is 04, followed by the $X$ coordinate and the $Y$ coordinate in big-endian notation each over 32 bytes. In order to convert to compressed format, we can replace the initial 04 with 02 or 03 (determined so that it has the same parity as the last byte), and remove the last 32 bytes.
  • in a bitstring which data already is in the desired compressed format of 33 bytes (264 bits), the first of which is 02or 03.

Note: In other conversion contexts I have met $X$ and $Y$ coordinates encoded as ASN.1 integer in the public key. Facing this, the textbook solution is to use an ASN.1 library. When doing without, be careful that the ASN.1 encoding of integers has variable length, so that it may be needed to remove one leading 00 (≲50% of the cases), or add one 00 (<0.4% of the cases) or even more (<0.002%).

Note: One might want to check that $X$, and $Y$ if available, form a valid secp256k1 public key, that is: for $p=2^{256}-2^{32}−977$ (the prime field order) it holds

  • $0<X<p$
  • if $Y$ is available, that $0<Y<p$ and $X^3+7-Y^2\bmod p=0$
  • otherwise, that $(X^3+7)^{(p-1)/2}\bmod p=1$
Fix
Source Link
fgrieu
  • 145.5k
  • 12
  • 319
  • 611

The question is for the standard 256-bit Elliptic Curve secp256k1. It wants the key in the format described in sec1v2, section 2.3.3 Elliptic-Curve-Point-to-Octet-String Conversion, with point compression, that is per 2.1/2.2.1/2.3/2.4

To decode the DER-encoded public key SubjectPublicKeyInfo or X.509 certificate, one can use this online tool, which accepts hex and base64. Most likely it will show the $X$ and $Y$ coordinates that have been encoded as ASN.1 integer in the public key.

The desired compressed public key starts with byte 02 or 03 (with the same parity as the $Y$ coordinate), followed by the $X$ coordinate in big-endian notation over 32 bytes. Further conversion to hexadecimal makes that a 66-character string.

When makingTo decode the DER-encoded public key SubjectPublicKeyInfo or X.509 certificate, one can use this online tool, which accepts hex and base64. As this programmaticallycomment points out, it will normally contain the point representative of the public key either

  • in a bitstring which data already is in the desired compressed format of 33 bytes (264 bits).
  • in a bitstring which data is in the uncompressed format of 65 bytes (520 bits), the first of which is 04, followed by the $X$ coordinate and the $Y$ coordinate in big-endian notation each over 32 bytes. In order to convert to compressed format, we can replace the initial 04 with 02 or 03 (with the same parity as the last byte), and remove the last 32 bytes.

Note: In other conversion contexts I have met $X$ and $Y$ coordinates encoded as ASN.1 integer in the public key. Facing this, the textbook solution is to use an ASN.1 library. When doing without, be careful that the ASN.1 encoding of integers has variable length, so that it may be needed to remove one leading 00 (≲50% of the cases), or add one 00 (<0.4% of the cases) or even more (<0.002%).

Note: After parsingOne might want to check that $X$, and $Y$ from the DER-encoded public key SubjectPublicKeyInfoif available, it's a good idea to check that they form a valid secp256k1 public key, that is: for $p=2^{256}-2^{32}−977$ (the prime field order) it holds

  • $0<X<p$
  • $0<Y<p$ if $Y$ is available, that
    • $0<Y<p$
    • $X^3+7-Y^2\bmod p=0$
  • $X^3-Y^2+7\bmod p=0$ otherwise, that $(X^3+7)^{(p-1)/2}\bmod p=1$

The question is for the standard 256-bit Elliptic Curve secp256k1. It wants the key in the format described in sec1v2, section 2.3.3 Elliptic-Curve-Point-to-Octet-String Conversion, with point compression, that is per 2.1/2.2.1/2.3/2.4

To decode the DER-encoded public key SubjectPublicKeyInfo or X.509 certificate, one can use this online tool, which accepts hex and base64. Most likely it will show the $X$ and $Y$ coordinates that have been encoded as ASN.1 integer in the public key.

The desired compressed public key starts with byte 02 or 03 (with the same parity as the $Y$ coordinate), followed by the $X$ coordinate in big-endian notation over 32 bytes. Further conversion to hexadecimal makes that a 66-character string.

When making this programmatically, the textbook solution is to use an ASN.1 library. When doing without, be careful that the ASN.1 encoding of integers has variable length, so that it may be needed to remove one leading 00 (≲50% of the cases), or add one 00 (<0.4% of the cases) or even more (<0.002%).

Note: After parsing $X$ and $Y$ from the DER-encoded public key SubjectPublicKeyInfo, it's a good idea to check that they form a valid secp256k1 public key, that is: for $p=2^{256}-2^{32}−977$ (the prime field order) it holds

  • $0<X<p$
  • $0<Y<p$
  • $X^3-Y^2+7\bmod p=0$

The question is for the standard 256-bit Elliptic Curve secp256k1. It wants the key in the format described in sec1v2, section 2.3.3 Elliptic-Curve-Point-to-Octet-String Conversion, with point compression, that is per 2.1/2.2.1/2.3/2.4

The desired compressed public key starts with byte 02 or 03 (with the same parity as the $Y$ coordinate), followed by the $X$ coordinate in big-endian notation over 32 bytes. Further conversion to hexadecimal makes that a 66-character string.

To decode the DER-encoded public key SubjectPublicKeyInfo or X.509 certificate, one can use this online tool, which accepts hex and base64. As this comment points out, it will normally contain the point representative of the public key either

  • in a bitstring which data already is in the desired compressed format of 33 bytes (264 bits).
  • in a bitstring which data is in the uncompressed format of 65 bytes (520 bits), the first of which is 04, followed by the $X$ coordinate and the $Y$ coordinate in big-endian notation each over 32 bytes. In order to convert to compressed format, we can replace the initial 04 with 02 or 03 (with the same parity as the last byte), and remove the last 32 bytes.

Note: In other conversion contexts I have met $X$ and $Y$ coordinates encoded as ASN.1 integer in the public key. Facing this, the textbook solution is to use an ASN.1 library. When doing without, be careful that the ASN.1 encoding of integers has variable length, so that it may be needed to remove one leading 00 (≲50% of the cases), or add one 00 (<0.4% of the cases) or even more (<0.002%).

Note: One might want to check that $X$, and $Y$ if available, form a valid secp256k1 public key, that is: for $p=2^{256}-2^{32}−977$ (the prime field order) it holds

  • $0<X<p$
  • if $Y$ is available, that
    • $0<Y<p$
    • $X^3+7-Y^2\bmod p=0$
  • otherwise, that $(X^3+7)^{(p-1)/2}\bmod p=1$
Polish
Source Link
fgrieu
  • 145.5k
  • 12
  • 319
  • 611
Loading
Add note
Source Link
fgrieu
  • 145.5k
  • 12
  • 319
  • 611
Loading
Polish
Source Link
fgrieu
  • 145.5k
  • 12
  • 319
  • 611
Loading
Source Link
fgrieu
  • 145.5k
  • 12
  • 319
  • 611
Loading