#๐Ÿ”’ How to load ECC Public Key from bytes data?

5 messages ยท Page 1 of 1 (latest)

loud moss
#

How to load ECC Public Key from bytes data? I need it to encrypt data.

alpine mapleBOT
#

@loud moss

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

loud moss
#

My current code:

class ECC:
    def __init__(self, private_key: Optional[bytes]):
        self.private_key = private_key

    def generate_keypair(self, store: Optional[bool] = False) -> bytes:
        private_key = ec.generate_private_key(
            ec.SECP521R1(),
            default_backend()
        )
        private_key_bytes = private_key.private_bytes(
            encoding = serialization.Encoding.PEM,
            format = serialization.PrivateFormat.PKCS8,
            encryption_algorithm = serialization.NoEncryption()
        )
        self.private_key = private_key_bytes
        open("./resources/private_key.pem", "wb").write(private_key_bytes) if store else None

        public_key = private_key.public_key()
        public_key_bytes = public_key.public_bytes(
            encoding = serialization.Encoding.PEM,
            format = serialization.PublicFormat.SubjectPublicKeyInfo
        )
        return public_key_bytes

    @staticmethod
    def encrypt(public_key: bytes):
        ... # How do I do this?
alpine mapleBOT
#

@loud moss

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.