I have a public key raw data (Which is extracted from NFC Chip of a machine readable travelling document.) However I want to execute the active authentication on cloud as well as the internal IC chip.
The snippet below shows the loading implementation with python's cryptography library.
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.serialization import load_der_public_key
_pub_key="6F81E03081DD300...."
pub_key_bytes = bytes.fromhex(_pub_key)
print(pub_key_bytes)
load_der_public_key(data = pub_key_bytes,backend=default_backend())
Which throws the error;
ValueError: Could not deserialize key data.
Which corresponds to this (in their documentation.)
Raised when an operation or function receives an argument that has the right type but an inappropriate value, and the situation is not described by a more precise exception such as IndexError
Also; I know the public key is in the correct format (at least on the beginning) since first byte is 0/, which is the required magic byte for DER formats.
I'm also aware of public key being 454 characters long, whereas RSA public keys have 256 bytes in length, (Which is equal to 512 hex characters.)
I tried adding right padding in order to complete the key to 512 characters as:
_pub_key = _pub_key+f"{'0'*(512-len(_pub_key))}"
Which also resulted in the same error.
PS: I know the key is valid because in successfully completes the authentication (sign + verify) in the microprocessor.