это программа реализующая ЭЦП вод код клиента import socket
import hashlib
from cryptography.hazmat.primitives.asymmetric import padding
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.serialization import load_pem_public_key
from cryptography.x509 import load_pem_x509_certificate
from tkinter import Tk, Label, Button, filedialog, messagebox

SERVER_HOST = "127.0.0.1"
SERVER_PORT = 65432
BUFFER_SIZE = 4096
FILE_NAME = "111.pdf"


class ESPClientApp:
    def __init__(self, root):
        self.root = root
        self.root.title("ЭЦП Клиент")

        Label(root, text="Электронная цифровая подпись", font=("Arial", 16)).pack(pady=10)

        Button(root, text="Подписать файл", command=self.sign_file, width=20).pack(pady=5)
        Button(root, text="Проверить подпись", command=self.verify_signature, width=20).pack(pady=5)

    def sign_file(self):
        try:
            with open(FILE_NAME, "rb") as f:
                file_data = f.read()

            # Отправка файла на сервер
            with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as client_socket:
                client_socket.connect((SERVER_HOST, SERVER_PORT))
                client_socket.sendall(b"sign")
                client_socket.recv(BUFFER_SIZE)  # ACK

                client_socket.sendall(FILE_NAME.encode())
                client_socket.recv(BUFFER_SIZE)  # ACK

                client_socket.sendall(file_data)
                client_socket.recv(BUFFER_SIZE)  # ACK

                # Получение подписи и сертификата
                signature = client_socket.recv(BUFFER_SIZE)
                client_socket.sendall(b"ACK")

                cert_data = client_socket.recv(BUFFER_SIZE)

            with open("signature.bin", "wb") as sig_file:
                sig_file.write(signature)

            with open("server_certificate.pem", "wb") as cert_file:
                cert_file.write(cert_data)

            messagebox.showinfo("Успех", "Файл подписан. Подпись и сертификат сохранены.")
        except Exception as e:
            messagebox.showerror("Ошибка", f"Не удалось подписать файл: {e}")

    def verify_signature(self):
        try:
            with open(FILE_NAME, "rb") as f:
                file_data = f.read()

            with open("signature.bin", "rb") as sig_file:
                signature = sig_file.read()

            with open("server_certificate.pem", "rb") as cert_file:
                cert_data = cert_file.read()

            cert = load_pem_x509_certificate(cert_data)
            public_key = cert.public_key()

            # Проверка подписи
            public_key.verify(
                signature,
                hashlib.sha256(file_data).digest(),
                padding.PKCS1v15(),
                hashes.SHA256()
            )

            messagebox.showinfo("Успех", "Подпись подтверждена.")
        except Exception as e:
            messagebox.showerror("Ошибка", f"Не удалось подтвердить подпись: {e}")


if __name__ == "__main__":
    root = Tk()
    app = ESPClientApp(root)
    root.mainloop()
Перепиши код сервера import socket
import hashlib
from cryptography.hazmat.primitives.asymmetric import padding
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.serialization import load_pem_public_key
from cryptography.x509 import load_pem_x509_certificate
from tkinter import Tk, Label, Button, filedialog, messagebox

SERVER_HOST = "127.0.0.1"
SERVER_PORT = 65432
BUFFER_SIZE = 4096
FILE_NAME = "111.pdf"


class ESPClientApp:
    def __init__(self, root):
        self.root = root
        self.root.title("ЭЦП Клиент")

        Label(root, text="Электронная цифровая подпись", font=("Arial", 16)).pack(pady=10)

        Button(root, text="Подписать файл", command=self.sign_file, width=20).pack(pady=5)
        Button(root, text="Проверить подпись", command=self.verify_signature, width=20).pack(pady=5)

    def sign_file(self):
        try:
            with open(FILE_NAME, "rb") as f:
                file_data = f.read()

            # Отправка файла на сервер
            with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as client_socket:
                client_socket.connect((SERVER_HOST, SERVER_PORT))
                client_socket.sendall(b"sign")
                client_socket.recv(BUFFER_SIZE)  # ACK

                client_socket.sendall(FILE_NAME.encode())
                client_socket.recv(BUFFER_SIZE)  # ACK

                client_socket.sendall(file_data)
                client_socket.recv(BUFFER_SIZE)  # ACK

                # Получение подписи и сертификата
                signature = client_socket.recv(BUFFER_SIZE)
                client_socket.sendall(b"ACK")

                cert_data = client_socket.recv(BUFFER_SIZE)

            with open("signature.bin", "wb") as sig_file:
                sig_file.write(signature)

            with open("server_certificate.pem", "wb") as cert_file:
                cert_file.write(cert_data)

            messagebox.showinfo("Успех", "Файл подписан. Подпись и сертификат сохранены.")
        except Exception as e:
            messagebox.showerror("Ошибка", f"Не удалось подписать файл: {e}")

    def verify_signature(self):
        try:
            with open(FILE_NAME, "rb") as f:
                file_data = f.read()

            with open("signature.bin", "rb") as sig_file:
                signature = sig_file.read()

            with open("server_certificate.pem", "rb") as cert_file:
                cert_data = cert_file.read()

            cert = load_pem_x509_certificate(cert_data)
            public_key = cert.public_key()

            # Проверка подписи
            public_key.verify(
                signature,
                hashlib.sha256(file_data).digest(),
                padding.PKCS1v15(),
                hashes.SHA256()
            )

            messagebox.showinfo("Успех", "Подпись подтверждена.")
        except Exception as e:
            messagebox.showerror("Ошибка", f"Не удалось подтвердить подпись: {e}")


if __name__ == "__main__":
    root = Tk()
    app = ESPClientApp(root)
    root.mainloop()