2

I use FALCON from liboqs with python wrapper from OQS. I have 2 python files, one for generating the public key, hashes and dump the result to an external file. While the second file will be use for verifying the hash from public key which will be extract from the external file.

Below is the full code for generating keys, hash and verify.

message = "Secret messagea".encode('utf-8')
print(message)

algo = "Falcon-512"

with oqs.Signature(algo) as falcon:
    print("\nDetails:")
    pprint(falcon.details)

    print("\n\n\n============================================")
    pub_key = falcon.generate_keypair()

    pri_key = falcon.export_secret_key()

    sign = falcon.sign(message)

    check = falcon.verify(message, sign, pub_key)

    print("\n Valid signature?", check)

What I have tried so far: dumping the key and hash directly to .txt on bytes format

Write code

with open(file, "wb") as file:
    file.write(key)
    file.write(hash)

Read Code

with open(file, "rb") as file:
    key = file.read()
    hash = file.read()

When extracting, the value is different

I tried converting to base64 however I when I decode it from base64 to byte the value is different. Below is the code to decode from base64

pub_key = base64.b64decode(pub_key)

I have research for using .pem file format, below is the function to write to .pem

from cryptography.hazmat.primitives import serialization

def writepem(key):
    pem_key = key.public_bytes(encoding=serialization.Encoding.PEM)
    with open(file, "wb") as file:
        file.write(pem_key)

However it resulted in error shown below

AttributeError: 'bytes' object has no attribute 'private_bytes'

I don't know how to use the cryptography module properly. Quite new to cryptographic programming.

Blake
  • 21
  • 1

0 Answers0