当前位置: 首页>>代码示例>>Python>>正文


Python Cipher.update方法代码示例

本文整理汇总了Python中M2Crypto.EVP.Cipher.update方法的典型用法代码示例。如果您正苦于以下问题:Python Cipher.update方法的具体用法?Python Cipher.update怎么用?Python Cipher.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在M2Crypto.EVP.Cipher的用法示例。


在下文中一共展示了Cipher.update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from M2Crypto.EVP import Cipher [as 别名]
# 或者: from M2Crypto.EVP.Cipher import update [as 别名]
def main():
    master_key = open('{{jenkins_home}}/secrets/master.key').read()
    hudson_secret_key = open(
        '{{jenkins_home}}/secrets/hudson.util.Secret'
    ).read()

    hashed_master_key = hashlib.sha256(master_key).digest()[:16]
    cipher = Cipher('aes_128_ecb', hashed_master_key, '', 0)
    v = cipher.update(hudson_secret_key)
    x = v + cipher.final()
    assert MAGIC in x

    k = x[:-16]
    k = k[:16]

    token = os.urandom(16).encode('hex')

    plaintext = token + MAGIC
    cipher = Cipher('aes_128_ecb', k, '', 1)
    v = cipher.update(plaintext)
    password = base64.b64encode(v + cipher.final())
    print password

    with open('/etc/jenkins_jobs/jenkins_jobs.ini', 'wb+') as f:
        f.write('\n'.join([
            '[jenkins]',
            'user=jenkins',
            'password=%s' % hashlib.md5(token).hexdigest(),
            'url=http://localhost:8080'
        ]))
开发者ID:abirjepatil,项目名称:akanda-ci,代码行数:32,代码来源:configure.py

示例2: encrypt_sn

# 需要导入模块: from M2Crypto.EVP import Cipher [as 别名]
# 或者: from M2Crypto.EVP.Cipher import update [as 别名]
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
开发者ID:lls3018,项目名称:mdmi,代码行数:9,代码来源:vpn_profile.py

示例3: decrypt

# 需要导入模块: from M2Crypto.EVP import Cipher [as 别名]
# 或者: from M2Crypto.EVP.Cipher import update [as 别名]
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 
开发者ID:yaksea,项目名称:lunchOrder,代码行数:9,代码来源:encryptHandler.py

示例4: decrypt

# 需要导入模块: from M2Crypto.EVP import Cipher [as 别名]
# 或者: from M2Crypto.EVP.Cipher import update [as 别名]
	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
开发者ID:mozilla,项目名称:weaveclient-python,代码行数:33,代码来源:weave.py

示例5: encrypt_hpwd

# 需要导入模块: from M2Crypto.EVP import Cipher [as 别名]
# 或者: from M2Crypto.EVP.Cipher import update [as 别名]
 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
开发者ID:gooseswan2,项目名称:bfmsite,代码行数:9,代码来源:models.py

示例6: decryptPasswd

# 需要导入模块: from M2Crypto.EVP import Cipher [as 别名]
# 或者: from M2Crypto.EVP.Cipher import update [as 别名]
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
开发者ID:lls3018,项目名称:mdmi,代码行数:9,代码来源:common.py

示例7: sym_decrypt

# 需要导入模块: from M2Crypto.EVP import Cipher [as 别名]
# 或者: from M2Crypto.EVP.Cipher import update [as 别名]
 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
开发者ID:fabregas,项目名称:fabnet_core,代码行数:9,代码来源:key_storage.py

示例8: do_encrypt

# 需要导入模块: from M2Crypto.EVP import Cipher [as 别名]
# 或者: from M2Crypto.EVP.Cipher import update [as 别名]
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 ''
开发者ID:wangdiwen,项目名称:system_mgm_tools,代码行数:30,代码来源:license.py

示例9: decrypt_text

# 需要导入模块: from M2Crypto.EVP import Cipher [as 别名]
# 或者: from M2Crypto.EVP.Cipher import update [as 别名]
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
开发者ID:carriercomm,项目名称:gluu-flask,代码行数:9,代码来源:common_helper.py

示例10: __encryptData

# 需要导入模块: from M2Crypto.EVP import Cipher [as 别名]
# 或者: from M2Crypto.EVP.Cipher import update [as 别名]
 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
开发者ID:CCardosoDev,项目名称:LinuxActivityLog,代码行数:9,代码来源:ClientProxy.py

示例11: testhash

# 需要导入模块: from M2Crypto.EVP import Cipher [as 别名]
# 或者: from M2Crypto.EVP.Cipher import update [as 别名]
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)
开发者ID:gooseswan2,项目名称:bfmsite,代码行数:10,代码来源:test.py

示例12: encryptData

# 需要导入模块: from M2Crypto.EVP import Cipher [as 别名]
# 或者: from M2Crypto.EVP.Cipher import update [as 别名]
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
开发者ID:andrewbird,项目名称:wader,代码行数:10,代码来源:aes.py

示例13: Decrypt

# 需要导入模块: from M2Crypto.EVP import Cipher [as 别名]
# 或者: from M2Crypto.EVP.Cipher import update [as 别名]
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 
开发者ID:windard,项目名称:Python_Lib,代码行数:11,代码来源:m2crypto_aes.py

示例14: encrypt

# 需要导入模块: from M2Crypto.EVP import Cipher [as 别名]
# 或者: from M2Crypto.EVP.Cipher import update [as 别名]
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                  
开发者ID:yaksea,项目名称:lunchOrder,代码行数:11,代码来源:encryptHandler.py

示例15: init_key_cipher

# 需要导入模块: from M2Crypto.EVP import Cipher [as 别名]
# 或者: from M2Crypto.EVP.Cipher import update [as 别名]
class M2CryptoEngine:
    K_CIPHER = None

    @classmethod
    def init_key_cipher(cls, prikey):
        cls.K_CIPHER = RSA.load_key_string(prikey)

    def __init__(self, encrypted_header=None):
        if encrypted_header:
            self.__enc_data = encrypted_header

            header = self.K_CIPHER.private_decrypt(encrypted_header, RSA.pkcs1_padding)
            secret = header[:32]
            iv = header[32:]
            op = DEC
        else:
            secret = self._get_random(32)
            iv = self._get_random(16)
            self.__enc_data = self.K_CIPHER.public_encrypt(secret+iv, RSA.pkcs1_padding)
            op = ENC

        self.__cipher = Cipher(alg='aes_128_cbc', key=secret, iv=iv, op=op)
        self.__cipher.set_padding(1)

    def _get_random(self, cnt):
        while True:
            data = Rand.rand_bytes(cnt)
            if data[0] != '\x00':
                return data

    def encrypt(self, data, finalize=False):
        end_data = self.__cipher.update(data)
        if finalize:
            end_data += self.__cipher.final()
        return end_data

    def decrypt(self, data, finalize=False):
        end_data = self.__cipher.update(data)
        if finalize:
            end_data += self.__cipher.final()
        return end_data

    def get_encrypted_header(self):
       return self.__enc_data 
开发者ID:fabregas,项目名称:nimbusfs-client,代码行数:46,代码来源:m2crypto_engine.py


注:本文中的M2Crypto.EVP.Cipher.update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。