def test_genkeys_write(self): kfilename = "temp.PEM" generateKeys(kfilename) with open(kfilename, mode='r') as keyfile: try: key = RSA.import_key(keyfile.read()) except: self.fail("generateKeys raises unexpected exception.")
def test_verify_ch(self, inp): msg = "hello there" keyfile = "temp.PEM" outfile = "out.txt" hashfile = "hash_out.txt" generateKeys(keyfile) inp.return_value = msg encryptRSA(keyfile,outfile) retVal = verify(keyfile,outfile,hashfile) self.assertEqual(1, retVal)
def test_encrypt_multiple_diffkey(self): msg = str.encode("Hello there") kfilename = "temp.PEM" kfilename2 = "temp2.PEM" generateKeys(kfilename2) with open(kfilename, mode='r') as keyfile: key = RSA.import_key(keyfile.read()) with open(kfilename2, mode='r') as keyfile: key2 = RSA.import_key(keyfile.read()) ciphertext = encrypt(msg, key) ciphertext2 = encrypt(msg, key2) self.assertNotEqual(ciphertext,ciphertext2)
def test_decryptRSA_cc_ck(self, inp): msg = "hello there" keyfile = "temp.PEM" ciphertextfile = "out.txt" originFilename = "origin.txt" generateKeys(keyfile) inp.return_value = msg encryptRSA(keyfile, ciphertextfile) with open(originFilename, mode="w") as ofile: ofile.write(msg) retVal = decryptRSA(keyfile, ciphertextfile, originFilename) self.assertEqual(1, retVal[0])
def test_decrypt_ccip_wkey(self): ori_msg = "Hello there" msg = str.encode(ori_msg) kfilename = "temp.PEM" generateKeys(kfilename) kfilename2 = "temp2.PEM" generateKeys(kfilename2) with open(kfilename, mode='r') as keyfile: key = RSA.import_key(keyfile.read()) with open(kfilename2, mode='r') as keyfile: key2 = RSA.import_key(keyfile.read()) ciphertext = encrypt(msg, key) with self.assertRaises(ValueError): plaintext = decrypt(ciphertext, key2)
def test_decryptRSA_wc_ck(self, inp): msg = "hello there" msg2 = "good bye" keyfile = "temp.PEM" generateKeys(keyfile) ciphertextfile2 = "out2.txt" originFilename = "origin.txt" inp.return_value = msg2 encryptRSA(keyfile, ciphertextfile2) with open(originFilename, mode="w") as ofile: ofile.write(msg) retVal = decryptRSA(keyfile, ciphertextfile2, originFilename) self.assertEqual(0, retVal[0])
print("Choose 2 for verification of the culprit") # Storing user input userInput = str(input("Enter (1 or 2): ")) # Checking the user input to determine which method to run if (userInput == '1'): # Simulation of buyer-seller scenario with the involvement of trusted third party # Buyer Side """ Generates Public and Private Key Pairs Returns: 1. Generated Key Pairs - saved into 'buyer.pem' file """ print("Buyer generates the public and private key pairs") generateKeys.generateKeys(buyerKey) print("Buyer's public and private key pairs is generated\n") """ Prompts Buyer for watermark RSA Encryption is done using Buyer's Private Key Returns: 1. Encrypted Watermark - saved into 'buyerCipher.txt' file 2. Buyer's Hash - saved into 'hash_buyerCipher.txt' file """ print("Buyer will now insert the watermark") encryptRSA.encryptRSA(buyerKey, buyerCipherFile) print( "Buyer's watermark is successfully encrypted with buyer's private key") print("Buyer's information hash is generated as well") print( "Buyer sends the encrypted watermark and information hash over to the seller"