コード例 #1
0
ファイル: test_bigfile.py プロジェクト: mlzharov/python-rsa
    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 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))
コード例 #3
0
ファイル: decode_rsa.py プロジェクト: qzane/usb_encrypt
def encode(msg):
    global pub_key
    with BytesIO(msg) as fi, BytesIO() as fo:    
        encrypt_bigfile(fi,fo,pub_key)
        fo.seek(0)
        msg=fo.read()
    return msg
コード例 #4
0
def encrypt(data, key):
    pub = rsa.PublicKey.load_pkcs1(key)
    out = StringIO()
    try:
        bigfile.encrypt_bigfile(StringIO(data), out, pub)
        return binascii.hexlify(out.getvalue())
    finally:
        out.close()
コード例 #5
0
ファイル: rnet_crypto.py プロジェクト: vulogov/rainbow-net
 def encrypt(self, data, key):
     if type(data) == type(u""):
         infile = StringIO(data.encode('utf8'))
     else:
         infile = StringIO(data)
     outfile = StringIO()
     bigfile.encrypt_bigfile(infile, outfile, key)
     return outfile.getvalue()
コード例 #6
0
ファイル: encrypt.py プロジェクト: missett/CryptoDropbox
	def encrypt_for_other( self , unencryptedFile , email ):
		with open( 'keys/' + email , 'r' ) as keyfile:
			pKey = rsa.PublicKey.load_pkcs1( keyfile.read() )
		
		destinationPath = self.settings.get_folder_path() + 'Outbox/' + email + time.strftime('-%H-%M-%S') 
		
		with open( destinationPath , 'w' ) as encryptedFile:
			with open( unencryptedFile , 'r' ) as openUnencryptedFile:
				bigfile.encrypt_bigfile( openUnencryptedFile , encryptedFile , pKey )
コード例 #7
0
ファイル: encrypt_data.py プロジェクト: liuzhao1006/ICOM
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()
コード例 #8
0
def file_read():
    # Input GUI - set vars
    openfile, out_dir, choice_site, choice_spec, encryption = input_gui()
    # clean headers
    outtext_temp = cleaner(openfile)
    # get chunks
    case_list, switch = mapper(outtext_temp, choice_site, choice_spec)
    if switch == 0:
        os.rmdir(out_dir)
        quit()
    else:
        print "2"
        print out_dir
        open_diff_os.openFolder(out_dir)
    fin_data, json_mrn, json_cases = reducer(case_list, choice_site)
    arr = [["JSON_CASES", json_cases], ["JSON_MRN", json_mrn],
           ["TABDELIM_CASES_OUT", fin_data], ["TEMP_CLEAN", outtext_temp]]

    if encryption == 1:
        crypt_dir = out_dir + "\\CRYPT"
        os.mkdir(crypt_dir)
        crypt_codes = ""

    for e in arr:
        print "22"
        fil = str(e[0]) + ".txt"
        print "33"
        filename = os.path.join(out_dir, fil)
        print "44"
        # filename = out_dir + "/" + e[0] + ".txt"
        print 'filename: ' + filename
        os.open(filename, os.O_RDWR | os.O_CREAT)
        with open(filename, 'wb') as out:
            out.write(str(e[1]))

        if encryption == 1:
            pubkey, privkey = rsa.newkeys(128, poolsize=1)
            print str(e[0]) + " KEYS: " + str(pubkey), str(privkey)

            crypt_codes = str(crypt_codes) + str(
                e[0]) + " KEYS: " + str(pubkey), str(privkey) + "\n"

            filecrypt = crypt_dir + "/CRYPTO_" + e[0] + ".txt"
            os.open(filecrypt, os.O_RDWR | os.O_CREAT)
            with open(filename, 'rb') as infile, open(filecrypt,
                                                      'wb') as outfile:
                encrypt_bigfile(infile, outfile, pubkey)

    if encryption == 1:
        filecrypts = crypt_dir + "/CRYPT_KEYS.txt"
        os.open(filecrypts, os.O_RDWR | os.O_CREAT)
        with open(filecrypts, 'wb') as out:
            out.write(str(crypt_codes))
コード例 #9
0
ファイル: encrypt_data.py プロジェクト: liuzhao1006/ICOM
def save_pem_data_common(f_path,pr):
	infile = pr.open('plain.txt','rb')
	outfile = open(os.path.join(f_path,pem_data_f_common_name),'wb+')
	bigfile.encrypt_bigfile(infile, outfile, default_pu)
	infile.close()
	outfile.close()
コード例 #10
0
ファイル: encrypt.py プロジェクト: missett/CryptoDropbox
	def encrypt( self , unencryptedFile , encryptedFile ):
		with open( unencryptedFile , 'r' ) as unencrypted:
			with open( encryptedFile , 'w' ) as encrypted:
				bigfile.encrypt_bigfile( unencrypted , encrypted , self.publicKey )
コード例 #11
0
ファイル: rsa_crypto.py プロジェクト: tsh/uni-10-semestr
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)