modified: README.md
modified: client/main.py modified: database/initdb.py new file: node/main.py modified: server/main.py modified: server/xiaomiandns.py
This commit is contained in:
@@ -1,51 +1,74 @@
|
||||
from cryptography.hazmat.primitives.asymmetric import rsa, padding
|
||||
from cryptography.hazmat.primitives import serialization, hashes
|
||||
import base64
|
||||
import random
|
||||
|
||||
# 生产随机域名
|
||||
def generate_domain():
|
||||
|
||||
|
||||
def generate_domain() -> str:
|
||||
domain = random.getrandbits(64)
|
||||
domain = hex(domain)[2:]
|
||||
return domain + ".xiaomian"
|
||||
|
||||
|
||||
# Generate a new RSA key pair
|
||||
private_key = rsa.generate_private_key(
|
||||
public_exponent=65537,
|
||||
key_size=2048
|
||||
)
|
||||
public_key = private_key.public_key()
|
||||
def generate_key():
|
||||
|
||||
# Convert the public key to bytes
|
||||
public_key_bytes = public_key.public_bytes(
|
||||
# Generate a new RSA key pair
|
||||
private_key = rsa.generate_private_key(
|
||||
public_exponent=65537,
|
||||
key_size=2048
|
||||
)
|
||||
public_key = private_key.public_key()
|
||||
|
||||
# Convert keys to bytes
|
||||
private_key_bytes = private_key.private_bytes(
|
||||
encoding=serialization.Encoding.PEM,
|
||||
format=serialization.PublicFormat.SubjectPublicKeyInfo
|
||||
)
|
||||
|
||||
# Encrypt a message using the public key
|
||||
message = b"Hello World"
|
||||
encrypted_message = public_key.encrypt(
|
||||
message,
|
||||
padding.OAEP(
|
||||
mgf=padding.MGF1(algorithm=hashes.SHA256()),
|
||||
algorithm=hashes.SHA256(),
|
||||
label=None
|
||||
format=serialization.PrivateFormat.PKCS8,
|
||||
encryption_algorithm=serialization.NoEncryption()
|
||||
)
|
||||
)
|
||||
|
||||
# Decrypt the message using the private key
|
||||
decrypted_message = private_key.decrypt(
|
||||
encrypted_message,
|
||||
padding.OAEP(
|
||||
mgf=padding.MGF1(algorithm=hashes.SHA256()),
|
||||
algorithm=hashes.SHA256(),
|
||||
label=None
|
||||
public_key_bytes = public_key.public_bytes(
|
||||
encoding=serialization.Encoding.PEM,
|
||||
format=serialization.PublicFormat.SubjectPublicKeyInfo
|
||||
)
|
||||
)
|
||||
print(decrypted_message)
|
||||
|
||||
# Encode bytes as base64
|
||||
private_key_base64 = base64.b64encode(private_key_bytes).decode('utf-8')
|
||||
public_key_base64 = base64.b64encode(public_key_bytes).decode('utf-8')
|
||||
|
||||
# private_key
|
||||
print(private_key_bytes)
|
||||
print(public_key_bytes)
|
||||
|
||||
|
||||
# # Encrypt a message using the public key
|
||||
# message = b"Hello World"
|
||||
# encrypted_message = public_key.encrypt(
|
||||
# message,
|
||||
# padding.OAEP(
|
||||
# mgf=padding.MGF1(algorithm=hashes.SHA256()),
|
||||
# algorithm=hashes.SHA256(),
|
||||
# label=None
|
||||
# )
|
||||
# )
|
||||
|
||||
# # Decrypt the message using the private key
|
||||
# decrypted_message = private_key.decrypt(
|
||||
# encrypted_message,
|
||||
# padding.OAEP(
|
||||
# mgf=padding.MGF1(algorithm=hashes.SHA256()),
|
||||
# algorithm=hashes.SHA256(),
|
||||
# label=None
|
||||
# )
|
||||
# )
|
||||
# print(decrypted_message)
|
||||
if __name__ == '__main__':
|
||||
print("Welcome to my xiaomiao tor network")
|
||||
domain = generate_domain()
|
||||
print(domain)
|
||||
|
||||
# print(domain)
|
||||
# public_key_base64 = base64.b64encode(public_key_bytes).decode('utf-8')
|
||||
# print(public_key_base64)
|
||||
# public_key = base64.b64decode(public_key_base64)
|
||||
# print(public_key)
|
||||
generate_key()
|
||||
|
||||
Reference in New Issue
Block a user