Reputation: 31
I create a pair of ed25519 keys and then used the cryptography Python library to sign an auth code with the private key:
private_key = serialization.load_ssh_private_key(open('ed25519', 'rb').read(), b'123456', default_backend())
with open('ed25519_py', 'wb') as dest_key:
dest_key.write(private_key.private_bytes(serialization.Encoding.PEM,
serialization.PrivateFormat.OpenSSH,
serialization.NoEncryption()
))
signature = private_key.sign(
authCodeBytes,
#padding.PSS(mgf=padding.MGF1(hashes.SHA256()), salt_length=padding.PSS.MAX_LENGTH),
#hashes.SHA256()
)
The signature looks like this: (I've made random edits)
b'>\xe1\xd0So8\xd1>\xf0\xa4\x18]_\x93A[z\x9c\x04\xf0oo\xc1\xa2\xe6\xdfL\x12z\xa3\x19\xbd\xeeOj\x80\xc2\xacbi\xb6\xd6\x9c*\xaa\xbe\xd4k\x1c\xab\xf8-\xbf\x10\ru\xa9\xe5lV1\x9e\xec\x0b'
Now I need to pass the signature in the body of an API call, but since it's in bytes, I cannot pass it:
TypeError: Object of type bytes is not JSON serializable
I am trying to decode the signature into a string but not able to find the encoding used for it.
Here are the docs for this signing procedure: https://cryptography.io/en/latest/hazmat/primitives/asymmetric/rsa/
Would really appreciate some help. I'm a beginner to cryptography.
Upvotes: 0
Views: 196