Exemplo n.º 1
0
####        or not ?                                           ####
####    - Save a file with the 40 first number of each         ####
####       merchant's key it encounters                        ####
####     -> inside the file, puts on each line, the unique     ####
####      number the merchant has produced and the customer's  ####
####      key, separated by a space                            ####
####    If it's fine, the bank with cash the check and add     ####
####        the line to the right file                         ####
###################################################################
from fileUtils import FileUtils
from RSAtools import RSAtools
import os.path
import sys

fileutils = FileUtils()
rsatools = RSAtools()
#Making sure the arguments and the files are there
clientkey_file = open(sys.argv[2], 'r')
merchantkey_file = open(sys.argv[3], 'r')

#Getting client's key and merchant's original key
clientkey_original = fileutils.recupKey(sys.argv[2])
merchant_key_original = fileutils.recupKey(sys.argv[3])

#Getting client's key ciphered by the bank and bank's private key
clientkeybanqueciphered = []
clientkeybanqueciphered.append(fileutils.readKey(sys.argv[1],2))
clientkeybanqueciphered.append(fileutils.readKey(sys.argv[1],3))

bank_publickey = fileutils.recupKey('banquePk')
#Deciphering the client's key
Exemplo n.º 2
0
import os
from RSAtools import RSAtools
from fileUtils import FileUtils
# This file generate :
# RSA public and private key for the bank, the commercant and the client
# Crypt of the public key of client by the bank SK, To garantee that the client is in this bank
if __name__ == '__main__' :
    rsa = RSAtools()
    fileUtil = FileUtils()
    # generation des clés RSA
    rsaClient = rsa.generateRSAkey(1024)
    rsaCommercant = rsa.generateRSAkey(1024)
    rsaBanque = rsa.generateRSAkey(1024)

    """n,e,d"""
    # ecriture des clés dans leur fichiers respectifs
    clientpk = open('clientPk','w')
    clientpk.write(str(rsaClient [0])+' '+str(rsaClient [1]))
    clientpk.close()
    clientsk = open('clientSk','w')
    clientsk.write(str(rsaClient [0])+' '+str(rsaClient [2]))
    clientsk.close()
    commercantpk = open('commercantPk','w')
    commercantpk.write(str(rsaCommercant [0])+' '+str(rsaCommercant [1]))
    commercantpk.close()
    commercantsk = open('commercantSk','w')
    commercantsk.write(str(rsaCommercant [0])+' '+str(rsaCommercant [2]))
    commercantsk.close()
    banquepk = open('banquePk','w')
    banquepk.write(str(rsaBanque [0])+' '+str(rsaBanque [1]))
    banquepk.close()
from fileUtils import FileUtils
from RSAtools import RSAtools

if( len(sys.argv) < 4 ):
    print("You need to put all of the arguments (invoice file, signed check and client's Pk)")
    sys.exit()

# file opening
try:
    invoice_file = open(sys.argv[1], 'r')
    signedcheck_file = open(sys.argv[2], 'r')
except (OSError, IOError) as error:
    print("Error reading file : ", error)
    sys.exit()
fileutils = FileUtils()
rsatools = RSAtools()

#Getting the infos from the files
clepub_client = fileutils.recupKey(sys.argv[3])
facture = Facture(sys.argv[1])
clepub_merchant_original = fileutils.recupKey("commercantPk")

bankPk = fileutils.recupKey("banquePk")

merchantkeyclientciphered = []
clientkeybanqueciphered = []

merchantkeyclientciphered.append( fileutils.readKey(sys.argv[2],0))
merchantkeyclientciphered.append( fileutils.readKey(sys.argv[2],1))

clientkeybanqueciphered.append(fileutils.readKey(sys.argv[2],2))