-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_keys.py
48 lines (38 loc) · 1.41 KB
/
generate_keys.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import secrets
import hashlib
from config.key_manager import KeyManager
import os
from typing import Dict
def generate_secure_key() -> str:
"""Generate a cryptographically secure key"""
return secrets.token_hex(32)
def generate_keys() -> Dict[str, str]:
"""Generate keys without hardcoding any values"""
try:
# Generate keys securely
private_key = generate_secure_key()
# In a real implementation, you would derive these from the private key
# using proper elliptic curve operations
# This is just a placeholder for demonstration
public_key_x = generate_secure_key()
public_key_y = generate_secure_key()
# Combine x and y coordinates for the full public key
public_key = f"{public_key_x},{public_key_y}"
keys = {
'private_key': private_key,
'public_key': public_key,
'pk_x': public_key_x,
'pk_y': public_key_y
}
# Store keys securely
key_manager = KeyManager()
key_manager.store_generated_keys(keys)
# Print only public information
print("Keys generated and stored securely.")
print(f"Public Key: {public_key}")
return keys
except Exception as e:
print(f"Error generating keys: {str(e)}")
return {}
if __name__ == "__main__":
generate_keys()