Python pyaes.AESModeOfOperationCTR() Examples

The following are 12 code examples of pyaes.AESModeOfOperationCTR(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pyaes , or try the search function .
Example #1
Source File: aesctr.py    From Telethon with MIT License 6 votes vote down vote up
def __init__(self, key, iv):
        """
        Initializes the AES CTR mode with the given key/iv pair.

        :param key: the key to be used as bytes.
        :param iv: the bytes initialization vector. Must have a length of 16.
        """
        # TODO Use libssl if available
        assert isinstance(key, bytes)
        self._aes = pyaes.AESModeOfOperationCTR(key)

        assert isinstance(iv, bytes)
        assert len(iv) == 16
        self._aes._counter._counter = list(iv) 
Example #2
Source File: decrypt.py    From RAASNet with GNU General Public License v3.0 5 votes vote down vote up
def decrypt_file_pyaes(file_name, key):
    aes = pyaes.AESModeOfOperationCTR(key)

    with open(file_name, 'rb') as fo:
        plaintext = fo.read()
    dec = aes.decrypt(plaintext)
    with open(file_name[:-6], 'wb') as fo:
        fo.write(dec) 
Example #3
Source File: RAASNet.py    From RAASNet with GNU General Public License v3.0 5 votes vote down vote up
def decrypt_file_pyaes(file_name, key):
    aes = pyaes.AESModeOfOperationCTR(key)

    with open(file_name, 'rb') as fo:
        plaintext = fo.read()
    dec = aes.decrypt(plaintext)
    with open(file_name[:-6], 'wb') as fo:
        fo.write(dec) 
Example #4
Source File: carpa.py    From circo with MIT License 5 votes vote down vote up
def decrypt(ciphertxt):
    """
    Decrypt credentails
    """
    hashed = pyscrypt.hash(PHRASE, SALT, 1024, 1, 1, 16)
    key = hashed.encode('hex')
    aes = pyaes.AESModeOfOperationCTR(key)
    cleartxt = aes.decrypt(ciphertxt.decode('hex'))
    return cleartxt 
Example #5
Source File: circo.py    From circo with MIT License 5 votes vote down vote up
def encrypt(cleartxt):
    hashed = pyscrypt.hash(PHRASE, SALT, 1024, 1, 1, 16)
    key = hashed.encode('hex')
    aes = pyaes.AESModeOfOperationCTR(key)
    ciphertxt = aes.encrypt(cleartxt)
    return ciphertxt.encode('hex') 
Example #6
Source File: jaula_chip.py    From circo with MIT License 5 votes vote down vote up
def decrypt(ciphertxt):
    hashed = pyscrypt.hash(PHRASE, SALT, 1024, 1, 1, 16)
    key = hashed.encode('hex')
    aes = pyaes.AESModeOfOperationCTR(key)
    cleartxt = aes.decrypt(ciphertxt.decode('hex'))
    return cleartxt 
Example #7
Source File: jaula_rpz.py    From circo with MIT License 5 votes vote down vote up
def decrypti(ciphertxt):
    hashed = pyscrypt.hash(PHRASE, SALT, 1024, 1, 1, 16)
    key = hashed.encode('hex')
    aes = pyaes.AESModeOfOperationCTR(key)
    cleartxt = aes.decrypt(ciphertxt.decode('hex'))
    return cleartxt 
Example #8
Source File: mtprotoproxy.py    From mtprotoproxy with MIT License 5 votes vote down vote up
def use_slow_bundled_cryptography_module():
    import pyaes

    msg = "To make the program a *lot* faster, please install cryptography module: "
    msg += "pip install cryptography\n"
    print(msg, flush=True, file=sys.stderr)

    class BundledEncryptorAdapter:
        __slots__ = ('mode', )

        def __init__(self, mode):
            self.mode = mode

        def encrypt(self, data):
            encrypter = pyaes.Encrypter(self.mode, pyaes.PADDING_NONE)
            return encrypter.feed(data) + encrypter.feed()

        def decrypt(self, data):
            decrypter = pyaes.Decrypter(self.mode, pyaes.PADDING_NONE)
            return decrypter.feed(data) + decrypter.feed()

    def create_aes_ctr(key, iv):
        ctr = pyaes.Counter(iv)
        return pyaes.AESModeOfOperationCTR(key, ctr)

    def create_aes_cbc(key, iv):
        mode = pyaes.AESModeOfOperationCBC(key, iv)
        return BundledEncryptorAdapter(mode)
    return create_aes_ctr, create_aes_cbc 
Example #9
Source File: crypt.py    From stash with MIT License 5 votes vote down vote up
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 
Example #10
Source File: crypt.py    From stash with MIT License 5 votes vote down vote up
def aes_decrypt(self, key, chunksize=64 * 1024):
        self.out_filename = self.out_filename or os.path.splitext(self.in_filename)[0]
        aes = pyaes.AESModeOfOperationCTR(key)

        with open(self.in_filename, 'rb') as infile:
            with open(self.out_filename, 'wb') as outfile:
                pyaes.decrypt_stream(aes, infile, outfile) 
Example #11
Source File: client.py    From HWI with MIT License 5 votes vote down vote up
def aes_setup(self, session_key):
        # Load keys and define encrypt/decrypt functions
        # - for CTR mode, we have different counters in each direction, so need two instances
        # - count must start at zero, and increment in LSB for each block.
        import pyaes

        self.encrypt_request = pyaes.AESModeOfOperationCTR(session_key, pyaes.Counter(0)).decrypt
        self.decrypt_response = pyaes.AESModeOfOperationCTR(session_key, pyaes.Counter(0)).encrypt 
Example #12
Source File: encryption.py    From ok-client with Apache License 2.0 5 votes vote down vote up
def aes_mode_of_operation(key):
    return pyaes.AESModeOfOperationCTR(from_safe_string(key))