Пример #1
0
    def test_encrypt_decrypt_bigfile(self):
        # Expected block size + 11 bytes padding
        pub_key, priv_key = rsa.newkeys((6 + 11) * 8)

        # Encrypt the file
        message = b('123456Sybren')
        infile = BytesIO(message)
        outfile = BytesIO()

        bigfile.encrypt_bigfile(infile, outfile, pub_key)

        # Test
        crypto = outfile.getvalue()

        cryptfile = BytesIO(crypto)
        clearfile = BytesIO()

        bigfile.decrypt_bigfile(cryptfile, clearfile, priv_key)
        self.assertEquals(clearfile.getvalue(), message)

        # We have 2x6 bytes in the message, so that should result in two
        # bigfile.
        cryptfile.seek(0)
        varblocks = list(varblock.yield_varblocks(cryptfile))
        self.assertEqual(2, len(varblocks))
Пример #2
0
def decode(msg):
    global pri_key
    with BytesIO(msg) as fi, BytesIO() as fo:    
        decrypt_bigfile(fi,fo,pri_key)
        fo.seek(0)
        msg=fo.read()
    return msg
Пример #3
0
    def test_encrypt_decrypt_bigfile(self):
        # Expected block size + 11 bytes padding
        pub_key, priv_key = rsa.newkeys((6 + 11) * 8)

        # Encrypt the file
        message = b('123456Sybren')
        infile = BytesIO(message)
        outfile = BytesIO()

        bigfile.encrypt_bigfile(infile, outfile, pub_key)

        # Test
        crypto = outfile.getvalue()

        cryptfile = BytesIO(crypto)
        clearfile = BytesIO()

        bigfile.decrypt_bigfile(cryptfile, clearfile, priv_key)
        self.assertEquals(clearfile.getvalue(), message)

        # We have 2x6 bytes in the message, so that should result in two
        # bigfile.
        cryptfile.seek(0)
        varblocks = list(varblock.yield_varblocks(cryptfile))
        self.assertEqual(2, len(varblocks))
Пример #4
0
def decrypt(data):
    out = StringIO()
    try:
        bigfile.decrypt_bigfile(StringIO(binascii.unhexlify(data.strip())),
                                out, PRIVATE_KEY)
        return out.getvalue()
    finally:
        out.close()
Пример #5
0
def test_bigfile():
	infile = open('plain.jpg','rb')
	outfile = open('enrcrypt.bin','wb+')
	bigfile.encrypt_bigfile(infile, outfile, default_pu)
	infile.close()
	outfile.close()
	
	infile = open('enrcrypt.bin','rb')
	outfile = open('decrypt.jpg','wb+')
	bigfile.decrypt_bigfile(infile, outfile, default_pr)
	infile.close()
	outfile.close()
Пример #6
0
def _load_pem_data_(f_path,f_name):
	data = (None,None)
	try:
		data_path = os.path.join(f_path,f_name)
		infile = open(data_path,'rb')
		outfile = KTemp_buffer()
		bigfile.decrypt_bigfile(infile, outfile, default_pr)
		infile.close()
		data = outfile.get()
		outfile.close()
		data = parse_data(data)
	except Exception as e:
		print('load pem data %s failed(%s)\n'%(f_path,e))
		#logger.warning('load pem data %s failed\n'%f_path)
		pass
	return data
Пример #7
0
# compile executable: python -O D:\path_to\pyinstaller-2.0\pyinstaller.py --onefile COPATHNLSHACK_DECRYPTOR_v1.PY
# ########additional Input GUI parameters and GUI call#########
title = "COPATH.NLS DECRYPTOR"
msg_fileopenbox = "Choose an encrypted *.txt file\nRemember to grab private-key"
file_type = "*.txt"
file_extension = ".txt"
msg_enterbox = "Enter the name for the folder to save decrypted file\nDefault: ~\COPATHNLS_OUTPUT_"
inputfile, outdir = inputgui.inputstuff(title, msg_fileopenbox, file_type,
                                        file_extension, msg_enterbox)

pk = enterbox(msg='Enter Private Key.',
              title=' ',
              default='',
              strip=True,
              image=None,
              root=None)
pkelements = pk.split(",")
privkey = rsa.PrivateKey(int(pkelements[0]), int(pkelements[1]),
                         int(pkelements[2]), int(pkelements[3]),
                         int(pkelements[4]))

fileid = re.compile(".*CRYPTO_(.*)\.txt")

outfileex = fileid.match(inputfile)
output = outfileex.group(1)

outputfile = outdir + "/DECRYPTED_" + output + ".txt"

with open(inputfile, 'rb') as infile, open(outputfile, 'wb') as outfile:
    decrypt_bigfile(infile, outfile, privkey)
Пример #8
0
	def decrypt( self , encryptedFile , unencryptedFile ):
		with open( encryptedFile , 'r' ) as encrypted:
			with open( unencryptedFile , 'w' ) as unencrypted:
				bigfile.decrypt_bigfile( encrypted , unencrypted , self.privateKey )
Пример #9
0
 def decrypt(self, data, key):
     infile = StringIO(data)
     outfile = StringIO()
     bigfile.decrypt_bigfile(infile, outfile, key)
     return outfile.getvalue()
Пример #10
0
import rsa
from rsa.bigfile import encrypt_bigfile, decrypt_bigfile

public_key, private_key = rsa.newkeys(2048)


with open('input.txt', 'rb') as infile, open('rsa_crypted', 'wb') as outfile:
    encrypt_bigfile(infile, outfile, public_key)

with open('rsa_crypted', 'rb') as infile, open('decrypted.txt', 'wb') as outfile:
    decrypt_bigfile(infile, outfile, private_key)