def signFile(self): self.cls() print(emblemas_31337.emblemas()) print("Firmando documento con algoritmo RSA\n####################################") if(self.verifyKeys()): PathFile=raw_input("Archivo a firmar: ") try: File=open(PathFile,'r') if(File!=None): Name=os.path.split(File.name); temp=len(Name)-1; Name=Name[temp]; ContentFile=File.read() SHA1File_HEX=hashlib.sha1(ContentFile).hexdigest() SHA1File_INT=int(SHA1File_HEX,16) print("\nHash:sha1\t\t\t\t### File") print("#####################################################") print(str(SHA1File_HEX)+"### "+str(Name)) print("#####################################################") File.close() firmante=raw_input("\nFirmar como: ") if(firmante==""): firmante="Anonymous" fecha=datetime.now() fecha=fecha.strftime("%d/%m/%Y") hora=strftime("%H:%M:%S") digital_signature=self.private_key_cipher(SHA1File_HEX) digital_signature0=digital_signature digital_signature="<signed>"+digital_signature.replace('\n','')+"</signed>" signed_file=open('signed_'+Name,"w") est_public_key='<pkn>'+hex(self.n).encode('base-64').replace('\n','')+'</pkn>'+'<pke>'+hex(self.e).encode('base-64').replace('\n','')+'</pke>' signed_file.write(ContentFile+digital_signature+est_public_key+"<signer>"+firmante+"</signer>"+"<date>"+fecha+"</date>"+"<time>"+hora+"</time>") print("\nSe firmo el documento "+Name+"\na nombre de "+firmante+'\ncon fecha '+fecha+' y hora '+hora) print("\n\nLa firma generada fue:\n#################################\n") print(digital_signature0) signed_file.close() print("El fichero se firmo correctamente") print("Enter para continuar...") raw_input() self.Menu() else: print("El fichero no existe") print("Enter para continuar...") raw_input() self.signFile() except: #ValueError: #print(ValueError) print("El fichero no existe") print("Enter para continuar...") raw_input() self.signFile() else: print('No hay llaves')
def Menu(self): try: self.cls() i = 0 while (i < 50): self.cls() print(emblemas_31337.emblemas()) i += 1 print("0) Generar Llaves") print("1) Firmar") print("2) Cifrar") print("3) Descifrar") print("4) Verificar firma") print("5) Salir") opc = input("\nElige una opción: ") if (opc == 0): self.genKeysRSA() elif (opc == 1): self.signFile() elif (opc == 2): pass elif (opc == 3): pass elif (opc == 4): self.check_signature() elif (opc == 5): self.exit() else: print("opción no valida") print("Enter para Continuar...") raw_input() self.Menu() except: #ValueError: #print(ValueError) self.Menu()
def Menu(self): try: self.cls() i=0 while(i<50): self.cls() print(emblemas_31337.emblemas()) i+=1 print("0) Generar Llaves") print("1) Firmar") print("2) Cifrar") print("3) Descifrar") print("4) Verificar firma") print("5) Salir") opc=input("\nElige una opción: ") if(opc==0): self.genKeysRSA() elif(opc==1): self.signFile() elif(opc==2): pass elif(opc==3): pass elif(opc==4): self.check_signature() elif(opc==5): self.exit() else: print("opción no valida") print("Enter para Continuar...") raw_input() self.Menu() except:#ValueError: #print(ValueError) self.Menu()
def signFile(self): self.cls() print(emblemas_31337.emblemas()) print( "Firmando documento con algoritmo RSA\n####################################" ) if (self.verifyKeys()): PathFile = raw_input("Archivo a firmar: ") try: File = open(PathFile, 'r') if (File != None): Name = os.path.split(File.name) temp = len(Name) - 1 Name = Name[temp] ContentFile = File.read() SHA1File_HEX = hashlib.sha1(ContentFile).hexdigest() SHA1File_INT = int(SHA1File_HEX, 16) print("\nHash:sha1\t\t\t\t### File") print( "#####################################################" ) print(str(SHA1File_HEX) + "### " + str(Name)) print( "#####################################################" ) File.close() firmante = raw_input("\nFirmar como: ") if (firmante == ""): firmante = "Anonymous" fecha = datetime.now() fecha = fecha.strftime("%d/%m/%Y") hora = strftime("%H:%M:%S") digital_signature = self.private_key_cipher(SHA1File_HEX) digital_signature0 = digital_signature digital_signature = "<signed>" + digital_signature.replace( '\n', '') + "</signed>" signed_file = open('signed_' + Name, "w") est_public_key = '<pkn>' + hex( self.n).encode('base-64').replace( '\n', '') + '</pkn>' + '<pke>' + hex( self.e).encode('base-64').replace( '\n', '') + '</pke>' signed_file.write(ContentFile + digital_signature + est_public_key + "<signer>" + firmante + "</signer>" + "<date>" + fecha + "</date>" + "<time>" + hora + "</time>") print("\nSe firmo el documento " + Name + "\na nombre de " + firmante + '\ncon fecha ' + fecha + ' y hora ' + hora) print( "\n\nLa firma generada fue:\n#################################\n" ) print(digital_signature0) signed_file.close() print("El fichero se firmo correctamente") print("Enter para continuar...") raw_input() self.Menu() else: print("El fichero no existe") print("Enter para continuar...") raw_input() self.signFile() except: #ValueError: #print(ValueError) print("El fichero no existe") print("Enter para continuar...") raw_input() self.signFile() else: print('No hay llaves')