24 lines
725 B
Python
24 lines
725 B
Python
import base64
|
|
import subprocess
|
|
|
|
# Открываем закрытый ключ DH
|
|
with open("dhkeyA.pem", "rb") as key_file:
|
|
key_data = key_file.read()
|
|
|
|
# Открываем открытый ключ DH
|
|
with open("dhpubB.pem", "rb") as peerkey_file:
|
|
peerkey_data = peerkey_file.read()
|
|
|
|
pkeyutl_command = ["openssl", "pkeyutl", "-derive", "-inkey", "dhkeyA.pem", "-peerkey", "dhpubB.pem", "-out", "secretShared.bin"]
|
|
subprocess.run(pkeyutl_command, input=key_data, check=True)
|
|
|
|
def shared_key_reader():
|
|
# Считываем общий секрет
|
|
with open("secretShared.bin", "rb") as shared_file:
|
|
shared_secret = shared_file.read().hex()
|
|
|
|
return shared_secret
|
|
|
|
print(shared_key_reader())
|
|
|
|
|