本文整理汇总了Python中M2Crypto.EVP.Cipher类的典型用法代码示例。如果您正苦于以下问题:Python Cipher类的具体用法?Python Cipher怎么用?Python Cipher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cipher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: encrypt_sn
def encrypt_sn(sn):
m=Cipher(alg = "aes_128_cbc", key = config['passout'], iv = '\x00' * 16, op = 1)
m.set_padding(padding=7)
v = m.update(sn)
v = v + m.final()
del m
return v
示例2: encrypt_hpwd
def encrypt_hpwd(self, clearpass):
key=settings.SECRET_KEY
iv=get_random_string(16)
cipher=Cipher(alg='aes_256_cbc', key=key, iv=iv, op=1)
v=cipher.update(clearpass) + cipher.final()
del cipher
return b64encode(v), iv
示例3: decrypt_text
def decrypt_text(encrypted_text, key):
# Porting from pyDes-based encryption (see http://git.io/htpk)
# to use M2Crypto instead (see https://gist.github.com/mrluanma/917014)
cipher = Cipher(alg="des_ede3_ecb", key=b"{}".format(key), op=0, iv="\0" * 16)
decrypted_text = cipher.update(base64.b64decode(b"{}".format(encrypted_text)))
decrypted_text += cipher.final()
return decrypted_text
示例4: decrypt
def decrypt(chunk, key):
cipher = Cipher(alg=ALG, key=key, iv=IV, op=0, key_as_bytes=0, padding=PADDING) # 0 is decrypt
cipher.set_padding(padding=m2.no_padding)
v = cipher.update(chunk)
v = v + cipher.final()
del cipher #需要删除
return v
示例5: decrypt
def decrypt(self, encryptedObject):
"""Given an encrypted object, decrypt it and return the plaintext value.
If necessary, will retrieve the private key and bulk encryption key
from the storage context associated with self."""
# Coerce JSON if necessary
if type(encryptedObject) == str or type(encryptedObject) == unicode:
encryptedObject = json.loads(encryptedObject)
# An encrypted object has two relevant fields
encryptionLabel = encryptedObject['encryption']
ciphertext = base64.decodestring(encryptedObject['ciphertext'])
# Go get the keying infromation if need it
if self.privateKey == None:
self.fetchPrivateKey()
if not encryptionLabel in self.bulkKeys:
self.fetchBulkKey(encryptionLabel)
# In case you were wondering, this is the same as this operation at the openssl command line:
# openssl enc -d -in data -aes-256-cbc -K `cat unwrapped_symkey.16` -iv `cat iv.16`
# Do the decrypt
logging.debug("Decrypting data record using bulk key %s" % encryptionLabel)
cipher = Cipher(alg='aes_256_cbc', key=self.bulkKeys[encryptionLabel], iv=self.bulkKeyIVs[encryptionLabel], op=0) # 0 is DEC
v = cipher.update(ciphertext)
v = v + cipher.final()
del cipher
logging.debug("Successfully decrypted data record")
return v
示例6: decryptPasswd
def decryptPasswd(buf, passKey, iv = '\x00' * 16):
cipher = Cipher(alg='aes_128_cbc', key=passKey, iv=iv, op=0) # 0 is decrypt
cipher.set_padding(padding=7)
v = cipher.update(buf)
v = v + cipher.final()
del cipher
return v
示例7: sym_decrypt
def sym_decrypt(self, key, data):
data = b64decode(data)
cipher = Cipher(alg='aes_128_cbc', key=key, iv=self.IV, op=DEC)
v = cipher.update(data)
v = v + cipher.final()
del cipher
return v
示例8: do_encrypt
def do_encrypt(file_name, encrypt_type): # encrypt_type: 0->decrypt, 1->encrypt
algorithm = 'bf_cbc'
key = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"
iv = "\x01\x02\x03\x04\x05\x06\x07\x08"
key_as_bytes = 0 # 0->use iv, 1->not use iv
algo_method = 'md5' # 'md5', 'sha1'
salt = '12345678'
iter_count = 1
padding = 1
if not os.path.isfile(file_name):
return ''
file = open(file_name, 'r')
content = file.read()
file.close()
try:
# constructor the EVP.Cipher obj
cipher_obj = Cipher(algorithm, key, iv, encrypt_type, key_as_bytes, algo_method, salt, iter_count, padding)
# use memory file obj
out = StringIO.StringIO()
out.write(cipher_obj.update(content))
out.write(cipher_obj.final())
return out.getvalue()
except Exception as e:
return ''
示例9: __encryptData
def __encryptData(self, key, iv, data):
data = str(data) + "\0" # <---- ----------
cipher = Cipher("aes_256_cbc", key, iv, ENC)
v = cipher.update(data)
v = v + cipher.final()
v = base64.b64encode(v)
return v
示例10: testhash
def testhash(request):
key=settings.SECRET_KEY
iv=Account.objects.get(id=1).random_str
data=b64decode('MTkcUSMxaxZytN4D3B7XEaPy5wNvAe0MHB1xNZeqZKo=')
cipher=Cipher(alg='aes_256_cbc', key=key, iv=iv, op=0)
v=cipher.update(data) + cipher.final()
del cipher
return HttpResponse(v)
示例11: encryptData
def encryptData(key, data):
iv = '\0' * 16
cipher = Cipher(alg=ALGS[len(key)], key=key, iv=iv, op=1)
encoded = cipher.update(data)
encoded = encoded + cipher.final()
return encoded
示例12: encrypt
def encrypt(chunk, key):
cipher = Cipher(alg=ALG, key=key, iv=IV, op=1, key_as_bytes=0,padding=PADDING) # 1 is encrypt
# padding 有时设置为1
cipher.set_padding(padding=m2.no_padding)
v = cipher.update(chunk)
v = v + cipher.final()
del cipher #需要删除
return v
示例13: Decrypt
def Decrypt(data):
'使用aes_128_ecb算法对数据解密'
# 将密文从16进制转为字节流
data = util.h2b(data)
cipher = Cipher(alg = 'aes_128_ecb', key = PRIVATE_KEY, iv = iv, op = DECRYPT_OP)
buf = cipher.update(data)
buf = buf + cipher.final()
del cipher
return buf
示例14: Encrypt
def Encrypt(data):
cipher = Cipher(alg = 'aes_128_ecb', key = PRIVATE_KEY, iv = iv, op = ENCRYPT_OP)
buf = cipher.update(data)
buf = buf + cipher.final()
del cipher
# 将明文从字节流转为16进制
output = ''
for i in buf:
output += '%02X' % (ord(i))
return output
示例15: Decrypt
def Decrypt(data):
# 将密文从16进制转为字节流
data = util.h2b(data)
cipher = Cipher(alg = 'aes_128_ecb', key = PRIVATE_KEY, iv = iv, op = DECRYPT_OP)
buf = cipher.update(data)
buf = buf + cipher.final()
del cipher
return buf
# print Decrypt('6C0D072989D9F7271EF1BD5AA1C830F2')