Esempio n. 1
0
File: Seal.py Progetto: evukelic/NOS
class Seal:
    """
    Class Seal represents digital seal.
    It combines digital envelope and digital signature.
    """
    def __init__(self, encryption_algorithm, key_type, rsa_key_size, message,
                 mode, sha_type):
        """
        Initialization method.
        :param encryption_algorithm: which symmetric algorithm will be used
        :param key_type: key size for the symmetric algorithm
        :param rsa_key_size: key size for the asymmetric algorithm
        :param message: encryption data
        :param mode: mode of the symmetric algorithm
        :param sha_type: SHA-2 type
        """
        self._sha = sha_type
        self._rsa_key = rsa_key_size
        # generate envelope
        self._envelope = Envelope(encryption_algorithm, key_type, rsa_key_size,
                                  message, mode)
        self._signature = None
        # envelope encryption result
        self._env_res = None

    def seal(self):
        """
        Seal method.
        """
        self._env_res = self._envelope.encrypt()
        message = str(self._envelope.cipher) + str(self._envelope.crypt_key)
        self._signature = Signature(self._sha, self._rsa_key, message)
        self._signature.sign()

    def unseal(self):
        """
        Unseal method.
        :return: original message
        """
        msg = self._envelope.decrypt(self._env_res)
        # verifies the signature
        verification = self._signature.verify()
        return msg, verification
Esempio n. 2
0
File: GUI.py Progetto: evukelic/NOS
def run_selected():
    new_window = Toplevel(root)
    new_window.geometry("400x270")
    calc_side_geometry(new_window)
    noError = True

    if button_value.get() == 1:
        algorithm = cat1
        mode = cat1_2
        rsa = cat1_3
    elif button_value.get() == 2:
        sha = cat2
        rsa = cat2_2
    else:
        algorithm = cat3
        mode = cat3_2
        rsa = cat3_3
        sha = cat3_4

    # check if everything is selected
    if button_value.get() == 1:
        task = 'Digitalna omotnica'
        if algorithm.get() == 'Select' or mode.get() == 'Select' or rsa.get(
        ) == 'Select':
            messagebox.showerror('Error', "Niste odabrali sve vrijednosti!")
            new_window.destroy()
            noError = False
    elif button_value.get() == 2:
        task = 'Digitalni potpis'
        if sha.get() == 'Select' or rsa.get() == 'Select':
            messagebox.showerror('Error', "Niste odabrali sve vrijednosti!")
            new_window.destroy()
            noError = False
    elif button_value.get() == 3:
        task = 'Digitalni pečat'
        if algorithm.get() == 'Select' or mode.get() == 'Select' or rsa.get(
        ) == 'Select' or sha.get() == 'Select':
            messagebox.showerror('Error', "Niste odabrali sve vrijednosti!")
            new_window.destroy()
            noError = False

    if text.get() == "" and noError:
        messagebox.showerror('Error', "Niste unijeli tekst!")
        new_window.destroy()
        noError = False

    if noError:
        Label(new_window, text=task.upper(),
              font=font_style_2).pack(pady=(2, 5))
        Label(new_window, text="Tekst koji ste unijeli:",
              font=font_style).pack(pady=(40, 5))
        Label(new_window, text=text.get()).pack()

        if button_value.get() == 1:
            Label(new_window,
                  text="Tekst koji je dobiven dekriptiranjem:",
                  font=font_style).pack(pady=(40, 5))
            envelope = Envelope(algorithm.get().split()[0],
                                algorithm.get().split()[1],
                                int(rsa.get().split()[1]), text.get(),
                                mode.get())
            sym_obj = envelope.encrypt()
            decrypted = envelope.decrypt(sym_obj)
            Label(new_window, text=decrypted).pack()

        elif button_value.get() == 2:
            Label(new_window,
                  text="Ishod digitalnog potpisivanja:",
                  font=font_style).pack(pady=(40, 5))
            signature = Signature(sha.get()[3:], int(rsa.get().split()[1]),
                                  text.get())
            signature.sign()
            verification = signature.verify()
            Label(new_window, text=verification).pack()

        else:
            seal = Seal(algorithm.get().split()[0],
                        algorithm.get().split()[1], int(rsa.get().split()[1]),
                        text.get(), mode.get(),
                        sha.get()[3:])
            seal.seal()
            decrypted, verification = seal.unseal()
            Label(new_window,
                  text="Tekst koji je dobiven dekriptiranjem:",
                  font=font_style).pack(pady=(20, 5))
            Label(new_window, text=decrypted).pack()
            Label(new_window,
                  text="Ishod digitalnog potpisivanja:",
                  font=font_style).pack(pady=(20, 5))
            Label(new_window, text=verification).pack()