當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。