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


Python SHA256.new方法代码示例

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


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

示例1: unlock

# 需要导入模块: from Crypto.Hash import SHA256 [as 别名]
# 或者: from Crypto.Hash.SHA256 import new [as 别名]
def unlock(vault_path, key):
    """
        Unlock legacy vault and retrieve content
    """

    f = open(vault_path, "rb")
    try:
        nonce, tag, ciphertext = [f.read(x) for x in (16, 16, -1)]
    finally:
        f.close()

    # Unlock Vault with key
    cipher = AES.new(get_hash(key), AES.MODE_EAX, nonce)
    data = cipher.decrypt_and_verify(ciphertext, tag)

    # Set vault content to class level var
    return json.loads(data.decode("utf-8")) 
开发者ID:gabfl,项目名称:vault,代码行数:19,代码来源:migration.py

示例2: prepare_items

# 需要导入模块: from Crypto.Hash import SHA256 [as 别名]
# 或者: from Crypto.Hash.SHA256 import new [as 别名]
def prepare_items(secrets, categories):
    """
        Prepare all secrets to the new import format
    """

    out = []
    for secret in secrets:
        out.append({
            'name': secret.get('name'),
            'url': None,  # Not supported in legacy database
            'login': secret.get('login'),
            'password': secret.get('password'),
            'notes': secret.get('notes'),
            'category': get_category_name(secret.get('category'), categories),
        })

    return out 
开发者ID:gabfl,项目名称:vault,代码行数:19,代码来源:migration.py

示例3: decrypt_secret

# 需要导入模块: from Crypto.Hash import SHA256 [as 别名]
# 或者: from Crypto.Hash.SHA256 import new [as 别名]
def decrypt_secret(data, key):
    if not data:
        return None

    aeskey = ""
    sha256 = SHA256.new()
    sha256.update(key)
    for i in range(1000):
        sha256.update(data[28:60])
    aeskey = sha256.digest()

    secret = ""
    aes = AES.new(aeskey)
    for key_offset in range(0, len(data) - 60, 16):
        if (key_offset + 16) <= len(data) - 60:
            secret = secret + aes.decrypt(data[60 + key_offset:60 + key_offset + 16])

    return secret 
开发者ID:HarmJ0y,项目名称:ImpDump,代码行数:20,代码来源:lsasecretsw2k8.py

示例4: verify

# 需要导入模块: from Crypto.Hash import SHA256 [as 别名]
# 或者: from Crypto.Hash.SHA256 import new [as 别名]
def verify(self, message, signature):
      """Verifies a message against a signature.

      Args:
        message: string, The message to verify.
        signature: string, The signature on the message.

      Returns:
        True if message was signed by the private key associated with the public
        key that this object was constructed with.
      """
      try:
        return PKCS1_v1_5.new(self._pubkey).verify(
            SHA256.new(message), signature)
      except:
        return False 
开发者ID:mortcanty,项目名称:earthengine,代码行数:18,代码来源:crypt.py

示例5: runTest

# 需要导入模块: from Crypto.Hash import SHA256 [as 别名]
# 或者: from Crypto.Hash.SHA256 import new [as 别名]
def runTest(self):
        """SHA256: 512/520 MiB test"""
        from Crypto.Hash import SHA256
        zeros = bchr(0x00) * (1024*1024)

        h = SHA256.new(zeros)
        for i in xrange(511):
            h.update(zeros)

        # This test vector is from PyCrypto's old testdata.py file.
        self.assertEqual('9acca8e8c22201155389f65abbf6bc9723edc7384ead80503839f49dcc56d767', h.hexdigest()) # 512 MiB

        for i in xrange(8):
            h.update(zeros)

        # This test vector is from PyCrypto's old testdata.py file.
        self.assertEqual('abf51ad954b246009dfe5a50ecd582fd5b8f1b8b27f30393853c3ef721e7fa6e', h.hexdigest()) # 520 MiB 
开发者ID:mortcanty,项目名称:earthengine,代码行数:19,代码来源:test_SHA256.py

示例6: decrypt_aes

# 需要导入模块: from Crypto.Hash import SHA256 [as 别名]
# 或者: from Crypto.Hash.SHA256 import new [as 别名]
def decrypt_aes(secret, key):
    """
    Based on code from http://lab.mediaservice.net/code/cachedump.rb
    """
    sha = SHA256.new()
    sha.update(key)
    for _i in range(1, 1000 + 1):
        sha.update(secret[28:60])
    aeskey = sha.digest()

    data = ""
    for i in range(60, len(secret), 16):
        aes = AES.new(aeskey, AES.MODE_CBC, '\x00' * 16)
        buf = secret[i : i + 16]
        if len(buf) < 16:
            buf += (16 - len(buf)) * "\00"
        data += aes.decrypt(buf)

    return data 
开发者ID:virtualrealitysystems,项目名称:aumfor,代码行数:21,代码来源:lsasecrets.py

示例7: decrypt_secret

# 需要导入模块: from Crypto.Hash import SHA256 [as 别名]
# 或者: from Crypto.Hash.SHA256 import new [as 别名]
def decrypt_secret(secret, key):
    """Python implementation of SystemFunction005.

    Decrypts a block of data with DES using given key.
    Note that key can be longer than 7 bytes."""
    decrypted_data = ''
    j = 0   # key index
    for i in range(0, len(secret), 8):
        enc_block = secret[i:i + 8]
        block_key = key[j:j + 7]
        des_key = hashdump.str_to_key(block_key)

        des = DES.new(des_key, DES.MODE_ECB)
        enc_block = enc_block + "\x00" * int(abs(8 - len(enc_block)) % 8)
        decrypted_data += des.decrypt(enc_block)

        j += 7
        if len(key[j:j + 7]) < 7:
            j = len(key[j:j + 7])

    (dec_data_len,) = struct.unpack("<L", decrypted_data[:4])
    return decrypted_data[8:8 + dec_data_len] 
开发者ID:virtualrealitysystems,项目名称:aumfor,代码行数:24,代码来源:lsasecrets.py

示例8: test_encryption_password

# 需要导入模块: from Crypto.Hash import SHA256 [as 别名]
# 或者: from Crypto.Hash.SHA256 import new [as 别名]
def test_encryption_password(password):
    """Tests the given password against what is saved in the global section of the config file as the encryption password.
       Returns True if the password is correct, False if it is incorrect or if the password is not set."""
    assert isinstance(password, str)

    validation_hash = _get_validation_hash()
    if validation_hash is None:
        return False
    
    from Crypto.Hash import SHA256
    h = SHA256.new()
    h.update(password.encode())
    initial_digest = h.digest() # this would be the AES key

    h = SHA256.new()
    h.update(initial_digest)
    if h.hexdigest().lower() != validation_hash:
        return False

    return True 
开发者ID:IntegralDefense,项目名称:ACE,代码行数:22,代码来源:crypto.py

示例9: encrypt_chunk

# 需要导入模块: from Crypto.Hash import SHA256 [as 别名]
# 或者: from Crypto.Hash.SHA256 import new [as 别名]
def encrypt_chunk(chunk, password=None):
    """Encrypts the given chunk of data and returns the encrypted chunk.
       If password is None then saq.ENCRYPTION_PASSWORD is used instead.
       password must be a byte string 32 bytes in length."""

    if password is None:
        password = saq.ENCRYPTION_PASSWORD

    assert isinstance(password, bytes)
    assert len(password) == 32

    iv = Crypto.Random.OSRNG.posix.new().read(AES.block_size)
    encryptor = AES.new(password, AES.MODE_CBC, iv)

    original_size = len(chunk)

    if len(chunk) % 16 != 0:
        chunk += b' ' * (16 - len(chunk) % 16)

    result = struct.pack('<Q', original_size) + iv + encryptor.encrypt(chunk)
    return result 
开发者ID:IntegralDefense,项目名称:ACE,代码行数:23,代码来源:crypto.py

示例10: decrypt_chunk

# 需要导入模块: from Crypto.Hash import SHA256 [as 别名]
# 或者: from Crypto.Hash.SHA256 import new [as 别名]
def decrypt_chunk(chunk, password=None):
    """Decrypts the given encrypted chunk with the given password and returns the decrypted chunk.
       If password is None then saq.ENCRYPTION_PASSWORD is used instead.
       password must be a byte string 32 bytes in length."""

    if password is None:
        password = saq.ENCRYPTION_PASSWORD

    assert isinstance(password, bytes)
    assert len(password) == 32


    _buffer = io.BytesIO(chunk)
    original_size = struct.unpack('<Q', _buffer.read(struct.calcsize('Q')))[0]
    iv = _buffer.read(16)
    chunk = _buffer.read()

    #original_size = struct.unpack('<Q', chunk[0:struct.calcsize('Q')])[0]
    #iv = chunk[struct.calcsize('Q'):struct.calcsize('Q') + 16]
    #chunk = chunk[struct.calcsize('Q') + 16:]
    decryptor = AES.new(password, AES.MODE_CBC, iv)
    result = decryptor.decrypt(chunk)
    return result[:original_size] 
开发者ID:IntegralDefense,项目名称:ACE,代码行数:25,代码来源:crypto.py

示例11: decrypt

# 需要导入模块: from Crypto.Hash import SHA256 [as 别名]
# 或者: from Crypto.Hash.SHA256 import new [as 别名]
def decrypt(key, filename):
	chunksize = 64 * 1024
	outputFile = filename.split('.hacklab')[0]


	with open(filename, 'rb') as infile:
		filesize = int(infile.read(16))
		IV = infile.read(16)
		decryptor = AES.new(key, AES.MODE_CBC, IV)

		with open(outputFile, 'wb') as outfile:

			while True:
				chunk = infile.read(chunksize)

				if len(chunk) == 0:
					break

				chunk = str(decryptor.decrypt(chunk))
				chunk = chunk.replace("0000hack1lab0000", "")
				outfile.write(chunk)
			outfile.truncate(filesize) 
开发者ID:bing0o,项目名称:Python-Scripts,代码行数:24,代码来源:crypto.py

示例12: get_encid

# 需要导入模块: from Crypto.Hash import SHA256 [as 别名]
# 或者: from Crypto.Hash.SHA256 import new [as 别名]
def get_encid(decid):
    """
    Generate an encrypted ID from a decrypted ID

    :param decid: Decrypted ID, type int
    :return: Encrypted ID, type str
    """
    try:
        int(decid)
    except:
        raise InvalidIDException('Decrypted ID must be int-castable')

    # Slashes are not URL-friendly; replace them with dashes
    # Also strip the base64 padding: it can be recovered.
    cipher = AES.new(config.ID_ENCRYPTION_KEY, AES.MODE_CBC, config.ID_ENCRYPTION_IV)
    return base64.b64encode(cipher.encrypt(_pad(str(decid))), ALTCHARS).rstrip('=') 
开发者ID:LINKIWI,项目名称:modern-paste,代码行数:18,代码来源:cryptography.py

示例13: ver5

# 需要导入模块: from Crypto.Hash import SHA256 [as 别名]
# 或者: from Crypto.Hash.SHA256 import new [as 别名]
def ver5(raw_str, sess, type):
    # for version 5
    # requires a session because the js makes an ajax request
    # in 256
    sha = comb[type]['sha']
    topost = comb[type]['topost']
    payload = comb[type]['payload']
    f = comb[type]['f']

    if(sha == ''):
        post_data = sess.post(topost, headers=post_headers, data=payload)
        obj_sha = SHA256.new(post_data.text.encode('utf8') )
        comb[type]['sha'] = binascii.unhexlify(obj_sha.hexdigest() )
        sha = comb[type]['sha']

    g = AES.new(sha, AES.MODE_CBC, f)
    jj = base64.b64decode(raw_str)
    #
    filled = g.decrypt(jj)
    return pkc.decode(filled).decode('utf8') 
开发者ID:wileyalt,项目名称:kissanime_dl,代码行数:22,代码来源:kissenc.py

示例14: decrypt

# 需要导入模块: from Crypto.Hash import SHA256 [as 别名]
# 或者: from Crypto.Hash.SHA256 import new [as 别名]
def decrypt(key, filename):
	chunksize = 64*1024

	with open(filename, 'rb') as infile:
		IV = infile.read(16)
		#print IV

		decryptor = AES.new(key, AES.MODE_CBC, IV)

		with open('decryted.txt','wb') as outfile:
			while True:
				chunk = infile.read(chunksize)

				if len(chunk) == 0:
					break

				outfile.write(decryptor.decrypt(chunk)) 
开发者ID:artikrh,项目名称:HackTheBox,代码行数:19,代码来源:decrypt.py

示例15: _build_auth_token_data

# 需要导入模块: from Crypto.Hash import SHA256 [as 别名]
# 或者: from Crypto.Hash.SHA256 import new [as 别名]
def _build_auth_token_data(
        self,
        auth_token_ticket,
        authenticator,
        private_key,
        **kwargs
    ):
        auth_token = dict(
            authenticator=authenticator,
            ticket=auth_token_ticket,
            **kwargs
            )
        auth_token = json.dumps(auth_token, sort_keys=True)
        if six.PY3:
            auth_token = auth_token.encode('utf-8')
        digest = SHA256.new()
        digest.update(auth_token)
        auth_token = base64.b64encode(auth_token)
        rsa_key = RSA.importKey(private_key)
        signer = PKCS1_v1_5.new(rsa_key)
        auth_token_signature = signer.sign(digest)
        auth_token_signature = base64.b64encode(auth_token_signature)
        return auth_token, auth_token_signature 
开发者ID:discogs,项目名称:python-cas-client,代码行数:25,代码来源:cas_client.py


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