예제 #1
0
    def encrypt(self, file_in_path, file_out_path):
        file_in = file(file_in_path)
        file_out = file(file_out_path, 'wb')
        pyaes.encrypt_stream(self.mode, file_in, file_out)

        # Close the files
        file_in.close()
        file_out.close()
예제 #2
0
def worker_main(filepath):
    """
    Real worker: doing all CPU intensive thing
    """
    aes = pyaes.AESModeOfOperationCBC(KEY_256, iv=IV_128)
    infile = file(filepath)
    outfile = file('/dev/null', 'wb')
    pyaes.encrypt_stream(aes, infile, outfile)
예제 #3
0
파일: crypt.py 프로젝트: zx110101/00
	def aes_encrypt(self, key=None, chunksize=64*1024):
		self.out_filename = self.out_filename or self.in_filename + '.enc'
		if key is None:
			key = base64.b64encode(os.urandom(32))[:32]
		aes = pyaes.AESModeOfOperationCTR(key)
		with open(self.in_filename, 'rb') as infile:
			with open(self.out_filename, 'wb') as outfile:
				pyaes.encrypt_stream(aes, infile, outfile)
		return key
예제 #4
0
 def encrypt_db(self):
     mode = pyaes.AESModeOfOperationCTR(self.key)
     if (os.path.isfile(USER_DIR + '/critter.db')):
         file_in = open(USER_DIR + '/critter.db', 'rb')
         file_out = open(USER_DIR + '/critter_enc.db', 'wb')
         pyaes.encrypt_stream(mode, file_in, file_out)
         file_in.close()
         file_out.close()
         os.remove(USER_DIR + '/critter.db')
def myaes_encrypt(key, in_file, out_file):
    key2 = "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    key2 = key + key2[len(key):]
    mode = pyaes.AESModeOfOperationCTR(key2.encode('utf-8'))
    file_in = open(in_file, 'rb')
    file_out = open(out_file, 'wb')
    pyaes.encrypt_stream(mode, file_in, file_out)
    file_in.close()
    file_out.close()
예제 #6
0
def aesMode(rawfile, newfile, operation, aes_keys):
    key = aes_keys.encode("utf-8")
    AES = pyaes.AESModeOfOperationCTR(key)
    file_in = open(rawfile, 'rb')
    file_out = open(newfile, 'wb')
    if operation == '加密':
        pyaes.encrypt_stream(AES, file_in, file_out)
    elif operation == '解密':
        pyaes.decrypt_stream(AES, file_in, file_out)
    file_in.close()
    file_out.close()
예제 #7
0
def szyfruj(nazwa_pliku_do_zaszyfrowania, klucz):
    file_in = open(nazwa_pliku_do_zaszyfrowania, 'rb')
    klucz = hashlib.sha256(klucz).digest()[:32]
    file_out = open('tmp.txt', 'wb+')
    mode = pyaes.AESModeOfOperationCTR(klucz)
    pyaes.encrypt_stream(mode, file_in, file_out)
    file_out.close()
    file_in.close()
    path = os.getcwd()
    if os.path.isfile(path + "\\" + nazwa_pliku_do_zaszyfrowania):
        os.remove(path + "\\" + nazwa_pliku_do_zaszyfrowania)
        os.rename(path + "\\tmp.txt", path + "\\" + nazwa_pliku_do_zaszyfrowania)
예제 #8
0
def aes_files(my_id, file_q, result_q):
    aes = pyaes.AESModeOfOperationCBC(KEY_256, iv=IV_128)
    while True:
        try:
            filepath = file_q.get_nowait(
            )  # no wait as the queue is pre-populated
        except Queue.Empty:
            return  # if can't get from file queue, we're done
        infile = file(filepath)
        outfile = file('/dev/null', 'wb')
        pyaes.encrypt_stream(aes, infile, outfile)
        result_q.put((my_id, filepath))
예제 #9
0
def crypter(infile, outfile, key=KEY_256, iv=IV_128, decrypt=False):
    # AES cipher in CBC operation
    aes = pyaes.AESModeOfOperationCBC(key, iv=iv)
    infile = file(infile)
    outfile = file(outfile, 'wb')
    if options.decrypt:
        pyaes.decrypt_stream(aes, infile, outfile)
    else:
        pyaes.encrypt_stream(aes, infile, outfile)
    # close file
    infile.close()
    outfile.close()
예제 #10
0
def aesMode(rawfilename, mode, operation, aes_bits, aes_keys):
    aes_mode = mode + '%s位' % aes_bits
    newfile = base.newFileName(rawfilename, aes_mode, operation)
    key = aes_keys.encode("utf-8")
    AES = pyaes.AESModeOfOperationCTR(key)
    file_in = open(rawfilename, 'rb')
    file_out = open(newfile, 'wb')
    if operation == '加密':
        pyaes.encrypt_stream(AES, file_in, file_out)
    elif operation == '解密':
        pyaes.decrypt_stream(AES, file_in, file_out)
    file_in.close()
    file_out.close()
예제 #11
0
    def encrypt(self, key, message):
        instream = BytesIO(message)
        outstream = BytesIO()

        iv = self.generate_iv()
        aes = pyaes.AESModeOfOperationCBC(key, iv=iv)

        pyaes.encrypt_stream(aes, instream, outstream)

        ciphertext = outstream.getvalue()

        instream.close()
        outstream.close()

        return iv + ciphertext
예제 #12
0
 def run(self):
     # As long as we weren't asked to stop, try to take new tasks from the
     # queue. The tasks are taken with a blocking 'get', so no CPU
     # cycles are wasted while waiting.
     # Also, 'get' is given a timeout, so stoprequest is always checked,
     # even if there's nothing in the queue.
     while not self.stoprequest.isSet():
         try:
             filepath = self.file_q.get(True, 0.05)
             aes = pyaes.AESModeOfOperationCBC(KEY_256, iv=IV_128)
             infile = file(filepath)
             outfile = file('/dev/null', 'wb')
             pyaes.encrypt_stream(aes, infile, outfile)
             self.result_q.put((self.name, filepath))
         except Queue.Empty:
             continue
def encryptfile(filename):
    """

    :rtype : object
    """
    key = bytes("This_key_for_demo_purposes_only!", 'utf-8')

    mode = pyaes.AESModeOfOperationCBC(key, iv=iv)

    file_in = open('eicar.com', 'r+')
    print("Encrypting file: ", filename)
    file_out = open('enceicar.bin', 'w')
    print("Encrypted file saved to enceicar.bin")
    pyaes.encrypt_stream(mode, file_in, file_out)
    file_in.close()
    file_out.close()
예제 #14
0
파일: myaes.py 프로젝트: aixiwang/eth_note
def myaes_encrypt(key,in_file,out_file):
    key2 = "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    key2 = key + key2[len(key):]
    mode = pyaes.AESModeOfOperationCTR(key2)
    file_in = file(in_file)
    file_out = file(out_file, 'wb')
    file_out_hex = file(out_file + '.hex', 'wb')
    pyaes.encrypt_stream(mode, file_in, file_out)
    
    file_in.close()
    file_out.close()
    
    file_out = file(out_file)    
    out = file_out.read()
    out_hex = out.encode('hex')
    file_out_hex.write(out_hex)
    
    file_out_hex.close()
    file_out.close()    
예제 #15
0
 def encrypt(self):
     shutil.make_archive(((str(sys.argv[1]))),"zip",".",str(sys.argv[1]))
     input_file_name = (str(sys.argv[1]) + ".zip")
     with open(input_file_name, encoding = "utf-8", errors = "ignore") as input_file:
         with open((input_file_name + ".encrypted"), 'wb+') as output_file:
             pyaes.encrypt_stream(self.mode, input_file, output_file)
예제 #16
0
import pyaes  # https://github.com/ricmoo/pyaes

# Alt: key_256 = os.urandom(32) # 32*8 = 256 bits
KEY_256 = "TodayMeColdNightSeeSnowFlyAcross"  # 今天我寒夜裡看雪飄過 32 bytes key
IV_128 = "SeaWide&SkyEmpty"  # 海闊天空 16 bytes IV

if __name__ == '__main__':
    # argparse
    parser = argparse.ArgumentParser(description='Slow encrypter')
    parser.add_argument("-i", "--infile", help="Path to input", required=True)
    parser.add_argument("-o",
                        "--outfile",
                        help="Path to output",
                        default='/dev/null')
    parser.add_argument("-d",
                        "--decrypt",
                        action='store_true',
                        default=False,
                        help="Decrypt instead of encrypt")
    args = parser.parse_args()
    # invoke
    aes = pyaes.AESModeOfOperationCBC(KEY_256, iv=IV_128)
    infile = file(args.infile)
    outfile = file(args.outfile, 'wb')
    if not args.decrypt:
        pyaes.encrypt_stream(aes, infile, outfile)
    else:
        pyaes.decrypt_stream(aes, infile, outfile)
    infile.close()
    outfile.close()
예제 #17
0
def aes_a_file(filepath):
    aes = pyaes.AESModeOfOperationCBC(KEY_256, iv=IV_128)
    infile = file(filepath)
    outfile = file('/dev/null', 'wb')
    pyaes.encrypt_stream(aes, infile, outfile)
예제 #18
0
def Encrypt(filename, aesMode):
    file_in = open(filename, 'r')
    file_out = open('encrypted.txt', 'a+b')
    pyaes.encrypt_stream(aesMode, file_in, file_out)
    file_in.close()
    file_out.close()
예제 #19
0
    passed = decrypted == plaintext
    cipher_length = len(ciphertext)
    print("  cipher-length=%(cipher_length)s passed=%(passed)s" % locals())

plaintext = os.urandom(1000)

for mode_name in pyaes.AESModesOfOperation:
    mode = pyaes.AESModesOfOperation[mode_name]
    print(mode.name + ' (stream operations)')

    kw = dict(key=key)
    if mode_name in ('cbc', 'cfb', 'ofb'):
        kw['iv'] = os.urandom(16)

    moo = mode(**kw)
    output = BytesIO()
    pyaes.encrypt_stream(moo, BytesIO(plaintext), output)
    output.seek(0)
    ciphertext = output.read()

    moo = mode(**kw)
    output = BytesIO()
    pyaes.decrypt_stream(moo, BytesIO(ciphertext), output)
    output.seek(0)
    decrypted = output.read()

    passed = decrypted == plaintext
    cipher_length = len(ciphertext)
    print("  cipher-length=%(cipher_length)s passed=%(passed)s" % locals())
예제 #20
0
파일: pyaes.py 프로젝트: tsh/uni-10-semestr
import pyaes
import hashlib

# Any mode of operation can be used; for this example CTR
inp = input('Password: '******'UTF-8')).hexdigest()[0:32], encoding='UTF-8')

# Create the mode of operation to encrypt with
mode = pyaes.AESModeOfOperationCTR(key)

# The input and output files
file_in = open('input.txt')
file_out = open('out.txt', 'wb')

# Encrypt the data as a stream, the file is read in 8kb chunks, be default
pyaes.encrypt_stream(mode, file_in, file_out)

# Close the files
file_in.close()
file_out.close()
예제 #21
0
import pyaes
import hashlib

# Any mode of operation can be used; for this example CTR
inp = input('Password: '******'UTF-8')).hexdigest()[0:32],
            encoding='UTF-8')

# Create the mode of operation to encrypt with
mode = pyaes.AESModeOfOperationCTR(key)

# The input and output files
file_in = open('input.txt')
file_out = open('out.txt', 'wb')

# Encrypt the data as a stream, the file is read in 8kb chunks, be default
pyaes.encrypt_stream(mode, file_in, file_out)

# Close the files
file_in.close()
file_out.close()
예제 #22
0
    cipher_length = len(ciphertext)
    print("  cipher-length=%(cipher_length)s passed=%(passed)s" % locals())

plaintext = os.urandom(1000)

for mode_name in pyaes.AESModesOfOperation:
    mode = pyaes.AESModesOfOperation[mode_name]
    print(mode.name + ' (stream operations)')

    kw = dict(key = key)
    if mode_name in ('cbc', 'cfb', 'ofb'):
        kw['iv'] = os.urandom(16)

    moo = mode(**kw)
    output = StringIO()
    pyaes.encrypt_stream(moo, StringIO(plaintext), output)
    output.seek(0)
    ciphertext = output.read()

    moo = mode(**kw)
    output = StringIO()
    pyaes.decrypt_stream(moo, StringIO(ciphertext), output)
    output.seek(0)
    decrypted = output.read()

    passed = decrypted == plaintext
    cipher_length = len(ciphertext)
    print("  cipher-length=%(cipher_length)s passed=%(passed)s" % locals())

# Issue #15
# https://github.com/ricmoo/pyaes/issues/15