Obtaining uncompacted public keys in compacted forms
Ethereum’s public keys are typically stored as compact bytes strings. This makes it difficult to decominate and easily recover for use in various applications, such as sending transactions or interacting with intelligent contracts. However, understanding the decompression process of these bytes sequences can help you work more efficiently with Ethereum data.
The BitCoralk Forum Response
A question similar to this was asked in the BitcoRontalk Forum: [https: //bitcoinalk.org/index.php? …] (https: //bitcoinalk.org/index.php? …). The answer suggests that you can use OpenSSL to decompress the compacted public key. Here is an example of how to do so in Python:
`Python
Import X509 Cryptography
Import base64
Loading the compacted public key of memory
compressed_public_key = b ‘\ x8c \ x05 \ x15 \ x00 \ x01 \ x00 \ x03 \ x04 \ x1e \ x07 \ x08 \ x10 \ x12 \ x12 \ x12 \ x12 \ x12 \ x12 3 \ x14 \ x15 \ x16 \ x17 ‘
Create a certificate object x.509 from the compacted public key
public_key = x509.load_pem_x509_certificate (compressed_public_key)
Convert the certificate to a rope coded by Pem
Pem_String = public_key.public_bytes (
coding = base64,
format = x509.der_cert_raw
) .Decode (“UTF-8”)
Print (Pem_String)
`
Explanation
- We started by loading the compacted public key using
x509.load_pem_x509_certificate ()
. This function obtains the sequence of compacted public key bytes as input.
- Then we created an object of certificate X.509 of the loaded public key using
x509.load_pem_x509_certificate ()
.
- To convert the certificate into a sequence encoded by PEM, we use
public_key.public_bytes (coding = base64, format = x509.der_cert_raw)
. This function takes the certificate and returns a sequence of bytes that contains the binary data from the public key.
- Finally, we print the uncontempted public key in hexadecimal format.
Using OpenSSL to decompress the public keys
To decompress the compacted public key using OpenSSL, you can use the OpenSSL tool. Here is an example:
`Bash
$ Openssl x509 -d -in
`
Replace
by the real bytes sequence of the compacted public key.
Observation
This method assumes that the compacted public key is in DER format (distinguished coding rules), which is the standard for X.509 certificates. If your public key is stored in a different format, you may need to use a different method to decompress it.
Understanding how to decompress compacted public keys using OpenSSL and Python, you can make your work with Ethereum data more efficient and convenient.