def otvori_omotnicu(self):

        envelope_data_items = fh.load(self.omotnica_path)
        envelope_data = bytes.fromhex(
            fh.concatList(fh.get_items("Envelope data", envelope_data_items)))

        envelope_crypt_key = fh.concatList(
            fh.get_items("Envelope crypt key", envelope_data_items))
        envelope_crypt_key = bytes.fromhex(envelope_crypt_key)

        rsa_b_tajni_items = fh.load(self.rsa_b_tajni)
        rsa_b_tajni_key = fh.concatList(
            fh.get_items("Secret key", rsa_b_tajni_items))
        rsa_b_tajni_key = bytes.fromhex(rsa_b_tajni_key)

        RSAkey = RSA.importKey(rsa_b_tajni_key)
        cipher = PKCS1_OAEP.new(RSAkey)
        desKey = cipher.decrypt(envelope_crypt_key)

        DESdekripter = DES.new(desKey, DES.MODE_OFB, self.iv)
        data = DESdekripter.decrypt(envelope_data)
        data = data.decode('utf-8', 'ignore')

        fh.writeIzlaz(self.izlaz_path, "Dekriptirana omotnica", "DES\n\tRSA",
                      data)
    def generiraj_omotnicu(self):

        ulaz_items = fh.load(self.ulaz_path)
        data = fh.concatList(fh.get_items('Data', ulaz_items))

        rsa_b_javni_items = fh.load(self.rsa_b_javni)
        rsa_b_javni_kljuc = bytes.fromhex(
            fh.concatList(fh.get_items('Secret key', rsa_b_javni_items)))

        if len(data) % 16 != 0:
            data += ' ' * (16 - len(data) % 16)

        desKey = os.urandom(8)

        self.iv = Random.new().read(DES.block_size)
        des_enkriptor = DES.new(desKey, DES.MODE_OFB, self.iv)
        kriptirano = str(des_enkriptor.encrypt(data).hex()).upper()

        RSAenkripter = RSA.importKey(rsa_b_javni_kljuc)
        enkripter = PKCS1_OAEP.new(RSAenkripter)
        desKeyKriptirano = enkripter.encrypt(desKey).hex().upper()

        keylen = len(fh.get_items("Secret key", rsa_b_javni_items))
        if keylen == 10:
            keylen = '0800'
        elif keylen == 19:
            keylen = '1000'
        else:
            keylen = '0400'

        fh.writeOmotnica(self.omotnica_path, 'Envelope', 'DES\n\tRSA',
                         '0010\n\t' + keylen, kriptirano, desKeyKriptirano)
Exemple #3
0
    def generiraj_pecat(self):

        ulaz_items = fh.load(self.ulaz_path)
        data = fh.concatList(fh.get_items('Data', ulaz_items))

        rsa_b_javni_items = fh.load(self.rsa_b_javni_path)
        rsa_b_javni_kljuc = bytes.fromhex(
            fh.concatList(fh.get_items('Secret key', rsa_b_javni_items)))

        if len(data) % 16 != 0:
            data += ' ' * (16 - len(data) % 16)

        desKey = os.urandom(8)

        self.iv = Random.new().read(DES.block_size)
        des_enkriptor = DES.new(desKey, DES.MODE_OFB, self.iv)
        kriptirano = str(des_enkriptor.encrypt(data).hex()).upper()

        RSAenkripter = RSA.importKey(rsa_b_javni_kljuc)
        enkripter = PKCS1_OAEP.new(RSAenkripter)
        desKeyKriptirano = enkripter.encrypt(desKey).hex().upper()

        keylen = len(fh.get_items("Secret key", rsa_b_javni_items))
        if keylen == 10:
            keylen = '0800'
        elif keylen == 19:
            keylen = '1000'
        else:
            keylen = '0400'

        fh.writeOmotnica(self.omotnica_path, 'Envelope', 'DES\n\tRSA',
                         '0010\n\t' + keylen, kriptirano, desKeyKriptirano)

        rsa_a_tajni_items = fh.load(self.rsa_a_tajni_path)

        kriptirano = kriptirano.encode()
        sha1 = hashlib.sha1(kriptirano)
        sazetak = str(sha1.hexdigest()).upper()

        fh.writeSha1(self.sazetak_path, "Data hash", "SHA-1", sazetak)

        sazetak = bytes.fromhex(sazetak)

        rsa_a_tajni_kljuc = bytes.fromhex(
            fh.concatList(fh.get_items("Secret key", rsa_a_tajni_items)))

        RSAenkripter = RSA.importKey(rsa_a_tajni_kljuc)
        potpis = str(RSAenkripter.sign(sazetak, '')[0])

        fh.writePotpis(self.potpis_path, "Signature", "SHA-1\n\tRSA", "0080",
                       potpis)
    def dekriptiraj_des(self):

        des_kljuc_items = fh.load(self.des_kljuc_path)
        des_key = str(
            fh.concatList(fh.get_items("Secret key", des_kljuc_items)))
        des_key = bytes.fromhex(des_key)

        ulaz_items = fh.load(self.des_izlaz_path)
        data = str(fh.concatList(fh.get_items("Data", ulaz_items)))
        data = bytes.fromhex(data)

        dekripter = DES.new(des_key, DES.MODE_OFB, self.iv)
        dekriptirano = dekripter.decrypt(data)
        dekriptirano = dekriptirano.decode('utf-8', 'ignore')

        fh.writeDES(self.des_ulaz_path, "DES dekriptiranje", "DES",
                    dekriptirano)
    def kriptiraj_des(self):

        des_kljuc_items = fh.load(self.des_kljuc_path)
        des_key = str(
            fh.concatList(fh.get_items("Secret key", des_kljuc_items)))
        des_key = bytes.fromhex(des_key)

        ulaz_items = fh.load(self.des_ulaz_path)
        data = str(fh.concatList(fh.get_items("Data", ulaz_items)))

        if len(data) % 16 != 0:
            data += ' ' * (16 - len(data) % 16)

        self.iv = Random.new().read(DES.block_size)
        des_enkriptor = DES.new(des_key, DES.MODE_OFB, self.iv)
        kriptirano = str(des_enkriptor.encrypt(data).hex()).upper()

        fh.writeDES(self.des_izlaz_path, "DES kriptiranje", "DES", kriptirano)
Exemple #6
0
    def generiraj_moj_sha1(self):

        ulaz_items = fh.load(self.ulaz_path)
        data = str(fh.concatList(fh.get_items("Data", ulaz_items)))

        data = fh.toHex(data)

        sha1 = moj_sha1.mojSha1(data)
        sazetak = str(sha1.digest()).upper()

        fh.writeSha1(self.sazetak_path, "Data hash", "MOJ SHA-1", sazetak)
Exemple #7
0
    def generiraj_sha1(self):

        ulaz_items = fh.load(self.ulaz_path)
        data = str(fh.concatList(fh.get_items("Data", ulaz_items)))

        data = data.encode('utf-8')

        sha1 = hashlib.sha1(data)
        sazetak = str(sha1.hexdigest()).upper()

        fh.writeSha1(self.sazetak_path, "Data hash", "SHA-1", sazetak)
    def provjeri_moj_potpis(self):

        ulaz_items = fh.load(self.ulaz_path)
        rsa_a_javni_items = fh.load(self.rsa_a_javni_path)
        potpis_items = fh.load(self.potpis_path)

        data = fh.concatList(fh.get_items("Data", ulaz_items))
        data = fh.toHex(data)

        rsa_a_javni_kljuc = bytes.fromhex(fh.concatList(fh.get_items("Secret key", rsa_a_javni_items)))
        potpis = str(fh.concatList(fh.get_items("Signature", potpis_items)))

        sha1 = moj_sha1.mojSha1(data)
        sazetak = bytes.fromhex(str(sha1.digest()).upper())

        RSAenkriptor = RSA.importKey(rsa_a_javni_kljuc)

        if RSAenkriptor.verify(sazetak, (int(potpis), '')):
            print("PORUKA JE AUTENTICNA")
        else:
            print("PORUKA NIJE AUTENTICNA")
    def generiraj_moj_potpis(self):

        ulaz_items = fh.load(self.ulaz_path)
        rsa_a_tajni_items = fh.load(self.rsa_a_tajni_path)

        data = fh.concatList(fh.get_items("Data", ulaz_items))
        data = fh.toHex(data)

        sha1 = moj_sha1.mojSha1(data)
        sazetak = str(sha1.digest()).upper()

        fh.writeSha1(self.sazetak_path, "Data hash", "MOJ SHA-1", sazetak)

        sazetak = bytes.fromhex(sazetak)

        rsa_a_tajni_kljuc = bytes.fromhex(fh.concatList(fh.get_items("Secret key", rsa_a_tajni_items)))

        RSAenkripter = RSA.importKey(rsa_a_tajni_kljuc)
        potpis = str(RSAenkripter.sign(sazetak, '')[0])

        fh.writePotpis(self.potpis_path, "Signature", "MOJ SHA-1\n\tRSA", "0080", potpis)
Exemple #10
0
    def otvori_pecat(self):

        omotnica_items = fh.load(self.omotnica_path)
        rsa_a_javni_items = fh.load(self.rsa_a_javni_path)
        potpis_items = fh.load(self.potpis_path)

        data = fh.concatList(fh.get_items("Envelope data", omotnica_items))

        rsa_a_javni_kljuc = bytes.fromhex(
            fh.concatList(fh.get_items("Secret key", rsa_a_javni_items)))
        potpis = str(fh.concatList(fh.get_items("Signature", potpis_items)))

        data = data.encode()
        sha1 = hashlib.sha1(data)
        sazetak = bytes.fromhex(str(sha1.hexdigest()).upper())

        RSAenkriptor = RSA.importKey(rsa_a_javni_kljuc)

        if RSAenkriptor.verify(sazetak, (int(potpis), '')):
            print("PORUKA JE AUTENTICNA")
        else:
            print("PORUKA NIJE AUTENTICNA")

        envelope_data_items = fh.load(self.omotnica_path)
        envelope_data = bytes.fromhex(
            fh.concatList(fh.get_items("Envelope data", envelope_data_items)))

        envelope_crypt_key = fh.concatList(
            fh.get_items("Envelope crypt key", envelope_data_items))
        envelope_crypt_key = bytes.fromhex(envelope_crypt_key)

        rsa_b_tajni_items = fh.load(self.rsa_b_tajni_path)
        rsa_b_tajni_key = fh.concatList(
            fh.get_items("Secret key", rsa_b_tajni_items))
        rsa_b_tajni_key = bytes.fromhex(rsa_b_tajni_key)

        RSAkey = RSA.importKey(rsa_b_tajni_key)
        cipher = PKCS1_OAEP.new(RSAkey)
        desKey = cipher.decrypt(envelope_crypt_key)

        DESdekripter = DES.new(desKey, DES.MODE_OFB, self.iv)
        data = DESdekripter.decrypt(envelope_data)
        data = data.decode('utf-8', 'ignore')

        fh.writeIzlaz(self.izlaz_path, "Dekriptirana omotnica", "DES\n\tRSA",
                      data)