本文整理汇总了Python中pyaes.AESModeOfOperationCTR方法的典型用法代码示例。如果您正苦于以下问题:Python pyaes.AESModeOfOperationCTR方法的具体用法?Python pyaes.AESModeOfOperationCTR怎么用?Python pyaes.AESModeOfOperationCTR使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyaes
的用法示例。
在下文中一共展示了pyaes.AESModeOfOperationCTR方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import AESModeOfOperationCTR [as 别名]
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)
示例2: decrypt_file_pyaes
# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import AESModeOfOperationCTR [as 别名]
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)
示例3: decrypt
# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import AESModeOfOperationCTR [as 别名]
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
示例4: encrypt
# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import AESModeOfOperationCTR [as 别名]
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')
示例5: decrypt
# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import AESModeOfOperationCTR [as 别名]
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
示例6: decrypti
# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import AESModeOfOperationCTR [as 别名]
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
示例7: use_slow_bundled_cryptography_module
# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import AESModeOfOperationCTR [as 别名]
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
示例8: aes_encrypt
# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import AESModeOfOperationCTR [as 别名]
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
示例9: aes_decrypt
# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import AESModeOfOperationCTR [as 别名]
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)
示例10: aes_setup
# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import AESModeOfOperationCTR [as 别名]
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
示例11: aes_mode_of_operation
# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import AESModeOfOperationCTR [as 别名]
def aes_mode_of_operation(key):
return pyaes.AESModeOfOperationCTR(from_safe_string(key))