# Public Key Encoding ## Metadata **Status**:: #x **Zettel**:: #zettel/fleeting **Created**:: [[2023-12-18]] **Reference**:: [[PyCryptodome]] ## SEC 1 Bytes Reference SEC 1: Elliptic Curve Cryptography (Version 2.0) section 2.3.3 (page 10). <http://www.secg.org/sec1-v2.pdf> - The point P is the origin: `0x00` - Compressed: `0x02 || X` or `0x03 || X` - Uncompressed: `0x04 || X || Y` ```python from Crypto import ECC key = ECC.generate(curve="secp256r1") pubkey = key.public_key() print(pubkey.export_key(format="SEC1").hex()) ``` > [!info] Output > ``` > -----BEGIN PUBLIC KEY----- > MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEZWZWTjespBPTrSlbhvqjfTasfQ0S > dW5YjjhKv1TP458rNQ3CNgJOkTqcS9FoZlsYIUrpC711ln3TALzgFyFppw== > -----END PUBLIC KEY----- > ``` ## PEM PEM is the format used by OpenSSL. ```python from Crypto import ECC key = ECC.generate(curve="secp256r1") pubkey = key.public_key() print(pubkey.export_key(format="PEM")) ``` > [!info] Output > ``` > 046566564e37aca413d3ad295b86faa37d36ac7d0d12756e588e384abf54cfe39f > 2b350dc236024e913a9c4bd168665b18214ae90bbd75967dd300bce0172169a7 > ```