Skip to content

Commit

Permalink
Create key_management.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Nov 26, 2024
1 parent 3f10f89 commit 8e9e1e4
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions QuantumNexusProtocol/src/cryptography/key_management.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives import serialization

class KeyManagement:
def __init__(self):
self.private_key = rsa.generate_private_key(
public_exponent=65537,
key_size=2048,
backend=default_backend()
)
self.public_key = self.private_key.public_key()

def save_keys(self, private_key_file, public_key_file):
with open(private_key_file, 'wb') as f:
f.write(self.private_key.private_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.TraditionalOpenSSL
))
with open(public_key_file, 'wb') as f:
f.write(self.public_key.public_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PublicFormat.SubjectPublicKeyInfo
))

# Example usage
if __name__ == "__main__":
km = KeyManagement()
km.save_keys('private_key.pem', 'public_key.pem')
print("Keys saved successfully.")

0 comments on commit 8e9e1e4

Please sign in to comment.