new file: client/dnssender.py new file: client/main.py new file: database/dns.db new file: database/initdb.py new file: server/main.py new file: server/xiaomiandns.py
52 lines
1.2 KiB
Python
52 lines
1.2 KiB
Python
from cryptography.hazmat.primitives.asymmetric import rsa, padding
|
|
from cryptography.hazmat.primitives import serialization, hashes
|
|
import random
|
|
|
|
# 生产随机域名
|
|
def generate_domain():
|
|
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()
|
|
|
|
# Convert the public key to bytes
|
|
public_key_bytes = public_key.public_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
|
|
)
|
|
)
|
|
|
|
# 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)
|