當前位置: 首頁>>代碼示例>>Python>>正文


Python scrypt.hash方法代碼示例

本文整理匯總了Python中scrypt.hash方法的典型用法代碼示例。如果您正苦於以下問題:Python scrypt.hash方法的具體用法?Python scrypt.hash怎麽用?Python scrypt.hash使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scrypt的用法示例。


在下文中一共展示了scrypt.hash方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _hash_scrypt

# 需要導入模塊: import scrypt [as 別名]
# 或者: from scrypt import hash [as 別名]
def _hash_scrypt(username, pwd, salt=None):
        """Hash username and password, generating salt value if required
        Use scrypt.

        :returns: base-64 encoded str.
        """
        if not scrypt_available:
            raise Exception("scrypt.hash required."
                            " Please install the scrypt library.")

        if salt is None:
            salt = os.urandom(32)

        assert len(salt) == 32, "Incorrect salt length"

        cleartext = "%s\0%s" % (username, pwd)
        h = scrypt.hash(cleartext, salt)

        # 's' for scrypt
        hashed = b's' + salt + h
        return b64encode(hashed) 
開發者ID:morpheus65535,項目名稱:bazarr,代碼行數:23,代碼來源:cork.py

示例2: _encode_uuid_map

# 需要導入模塊: import scrypt [as 別名]
# 或者: from scrypt import hash [as 別名]
def _encode_uuid_map(userid, uuid, passwd):
    data = 'userid:%s:uuid:%s' % (userid, uuid)

    # FIXME scrypt.encrypt is broken in windows.
    # This is a quick hack. The hostname might not be unique enough though.
    # We could use a long random hash per entry and store it in the file.
    # Other option is to use a different KDF that is supported by cryptography
    # (ie, pbkdf)

    if IS_WIN:
        key = scrypt.hash(passwd, socket.gethostname())
        key = base64.urlsafe_b64encode(key[:32])
        f = Fernet(key, backend=crypto_backend)
        encrypted = f.encrypt(data)
    else:
        encrypted = scrypt.encrypt(data, passwd, maxtime=0.05)
    return base64.urlsafe_b64encode(encrypted) 
開發者ID:leapcode,項目名稱:bitmask-dev,代碼行數:19,代碼來源:uuid_map.py

示例3: _decode_uuid_line

# 需要導入模塊: import scrypt [as 別名]
# 或者: from scrypt import hash [as 別名]
def _decode_uuid_line(line, passwd):
    decoded = base64.urlsafe_b64decode(line)
    if IS_WIN:
        key = scrypt.hash(passwd, socket.gethostname())
        key = base64.urlsafe_b64encode(key[:32])
        try:
            f = Fernet(key, backend=crypto_backend)
            maybe_decrypted = f.decrypt(key)
        except Exception:
            return None
    else:
        try:
            maybe_decrypted = scrypt.decrypt(decoded, passwd, maxtime=0.1)
        except scrypt.error:
            return None
    match = re.findall("userid\:(.+)\:uuid\:(.+)", maybe_decrypted)
    if match:
        return match[0] 
開發者ID:leapcode,項目名稱:bitmask-dev,代碼行數:20,代碼來源:uuid_map.py

示例4: pay_to_address_script

# 需要導入模塊: import scrypt [as 別名]
# 或者: from scrypt import hash [as 別名]
def pay_to_address_script(cls, address):
        """Return a pubkey script that pays to a pubkey hash.

        Pass the address (either P2PKH or P2SH) in base58 form.
        """
        raw = cls.DECODE_CHECK(address)

        # Require version byte(s) plus hash160.
        verbyte = -1
        verlen = len(raw) - 20
        if verlen > 0:
            verbyte, hash160 = raw[:verlen], raw[verlen:]

        if verbyte == cls.P2PKH_VERBYTE:
            return cls.hash160_to_P2PKH_script(hash160)
        if verbyte in cls.P2SH_VERBYTES:
            return ScriptPubKey.P2SH_script(hash160)

        raise CoinError('invalid address: {}'.format(address)) 
開發者ID:lbryio,項目名稱:torba,代碼行數:21,代碼來源:coins.py

示例5: bf

# 需要導入模塊: import scrypt [as 別名]
# 或者: from scrypt import hash [as 別名]
def bf(h, dictionary):

    f = open(dictionary, 'r')
    lines = f.readlines()
    lines = lines.replace('\n', '')
    print('\033[1;34m[*]\033[0m Starting Brute Force - hash = ' + h)
    for i in lines:
    
    
        h2 = scrypt.hash(i, salt)
    
        if h == h2:
    
            print('\033[1;32m[+]\033[0m Hash Cracked! - Password = ' + i)
            exit()
    print('\033[1;31m[-]\033[0m Hash could not be cracked!') 
開發者ID:lockedbyte,項目名稱:cryptovenom,代碼行數:18,代碼來源:bruteforce.py

示例6: set_scrypt_library

# 需要導入模塊: import scrypt [as 別名]
# 或者: from scrypt import hash [as 別名]
def set_scrypt_library(library = SCRYPT_LIBRARY_AUTO):
  '''Sets the scrypt library implementation to use.'''

  global SCRYPT_LIBRARY
  global scrypt_proof_of_work

  if library == SCRYPT_LIBRARY_LTC:
    import ltc_scrypt
    scrypt_proof_of_work = ltc_scrypt.getPoWHash
    SCRYPT_LIBRARY = library

  elif library == SCRYPT_LIBRARY_SCRYPT:
    import scrypt as NativeScrypt
    scrypt_proof_of_work = lambda header: NativeScrypt.hash(header, header, 1024, 1, 1, 32)
    SCRYPT_LIBRARY = library

  # Try to load a faster version of scrypt before using the pure-Python implementation
  elif library == SCRYPT_LIBRARY_AUTO:
    try:
      set_scrypt_library(SCRYPT_LIBRARY_LTC)
    except Exception, e:
      try:
        set_scrypt_library(SCRYPT_LIBRARY_SCRYPT)
      except Exception, e:
        set_scrypt_library(SCRYPT_LIBRARY_PYTHON) 
開發者ID:ricmoo,項目名稱:nightminer,代碼行數:27,代碼來源:nightminer.py

示例7: _verify_password

# 需要導入模塊: import scrypt [as 別名]
# 或者: from scrypt import hash [as 別名]
def _verify_password(self, username, pwd, salted_hash):
        """Verity username/password pair against a salted hash

        :returns: bool
        """
        assert isinstance(salted_hash, type(b''))
        decoded = b64decode(salted_hash)
        hash_type = decoded[0]
        if isinstance(hash_type, int):
            hash_type = chr(hash_type)

        salt = decoded[1:33]

        if hash_type == 'p':  # PBKDF2
            h = self._hash_pbkdf2(username, pwd, salt)
            return salted_hash == h

        if hash_type == 's':  # scrypt
            h = self._hash_scrypt(username, pwd, salt)
            return salted_hash == h

        raise RuntimeError("Unknown hashing algorithm in hash: %r" % decoded) 
開發者ID:morpheus65535,項目名稱:bazarr,代碼行數:24,代碼來源:cork.py

示例8: derive_key

# 需要導入模塊: import scrypt [as 別名]
# 或者: from scrypt import hash [as 別名]
def derive_key(salt: str, passphrase: str, hd: bool = True) -> \
        Union[int, Tuple[int, bytes]]:
    key_length = 64 if hd else 32  # type: int

    t1 = and_split(bytes(salt, "utf-8"))  # type: Tuple[bytes, bytes]
    salt1, salt2 = t1
    t2 = and_split(bytes(passphrase, "utf-8"))  # type: Tuple[bytes, bytes]
    pass1, pass2 = t2

    scrypt_key = scrypt.hash(
        pass1, salt1,
        N=1 << 18, buflen=key_length)  # type: bytes
    pbkdf2_key = pbkdf2.PBKDF2(
        pass2, salt2,
        iterations=1 << 16,
        digestmodule=SHA256).read(key_length)  # type: bytes
    merged = xor_merge(scrypt_key, pbkdf2_key)  # type: bytes

    if hd:
        secret_exp = int(merged[0:32].hex(), 16)  # type: int
        chain_code = merged[32:]  # type: bytes
        return secret_exp, chain_code

    return int(merged.hex(), 16) 
開發者ID:metamarcdw,項目名稱:nowallet,代碼行數:26,代碼來源:keys.py

示例9: addr_to_pubkeyhash

# 需要導入模塊: import scrypt [as 別名]
# 或者: from scrypt import hash [as 別名]
def addr_to_pubkeyhash(address, as_hex=False, encoding=None):
    """
    Convert base58 or bech32 address to public key hash

    Wrapper for the :func:`addr_base58_to_pubkeyhash` and :func:`addr_bech32_to_pubkeyhash` method

    :param address: Crypto currency address in base-58 format
    :type address: str
    :param as_hex: Output as hexstring
    :type as_hex: bool
    :param encoding: Address encoding used: base58 or bech32. Default is base58. Try to derive from address if encoding=None is provided
    :type encoding: str

    :return bytes, str: public key hash
    """

    if encoding == 'base58' or encoding is None:
        try:
            pkh = addr_base58_to_pubkeyhash(address, as_hex)
        except EncodingError:
            pkh = None
        if pkh is not None:
            return pkh
    if encoding == 'bech32' or encoding is None:
        return addr_bech32_to_pubkeyhash(address, as_hex=as_hex) 
開發者ID:1200wd,項目名稱:bitcoinlib,代碼行數:27,代碼來源:encoding.py

示例10: pubkeyhash_to_addr_base58

# 需要導入模塊: import scrypt [as 別名]
# 或者: from scrypt import hash [as 別名]
def pubkeyhash_to_addr_base58(pubkeyhash, prefix=b'\x00'):
    """
    Convert public key hash to base58 encoded address

    >>> pubkeyhash_to_addr_base58('21342f229392d7c9ed82c932916cee6517fbc9a2')
    '142Zp9WZn9Fh4MV8F3H5Dv4Rbg7Ja1sPWZ'

    :param pubkeyhash: Public key hash
    :type pubkeyhash: bytes, str
    :param prefix: Prefix version byte of network, default is bitcoin '\x00'
    :type prefix: str, bytes

    :return str: Base-58 encoded address
    """
    # prefix = to_bytes(prefix)
    key = to_bytearray(prefix) + to_bytearray(pubkeyhash)
    addr256 = key + double_sha256(key)[:4]
    return change_base(addr256, 256, 58) 
開發者ID:1200wd,項目名稱:bitcoinlib,代碼行數:20,代碼來源:encoding.py

示例11: get_args

# 需要導入模塊: import scrypt [as 別名]
# 或者: from scrypt import hash [as 別名]
def get_args():
  parser = optparse.OptionParser()
  parser.add_option("-t", "--time", dest="time", default=int(time.time()), 
                   type="int", help="the (unix) time when the genesisblock is created")
  parser.add_option("-z", "--timestamp", dest="timestamp", default="The Times 03/Jan/2009 Chancellor on brink of second bailout for banks",
                   type="string", help="the pszTimestamp found in the coinbase of the genesisblock")
  parser.add_option("-n", "--nonce", dest="nonce", default=0,
                   type="int", help="the first value of the nonce that will be incremented when searching the genesis hash")
  parser.add_option("-a", "--algorithm", dest="algorithm", default="SHA256",
                    help="the PoW algorithm: [SHA256|scrypt|X11|X13|X15]")
  parser.add_option("-p", "--pubkey", dest="pubkey", default="04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f",
                   type="string", help="the pubkey found in the output script")
  parser.add_option("-v", "--value", dest="value", default=5000000000,
                   type="int", help="the value in coins for the output, full value (exp. in bitcoin 5000000000 - To get other coins value: Block Value * 100000000)")
  parser.add_option("-b", "--bits", dest="bits",
                   type="int", help="the target in compact representation, associated to a difficulty of 1")

  (options, args) = parser.parse_args()
  if not options.bits:
    if options.algorithm == "scrypt" or options.algorithm == "X11" or options.algorithm == "X13" or options.algorithm == "X15":
      options.bits = 0x1e0ffff0
    else:
      options.bits = 0x1d00ffff
  return options 
開發者ID:lhartikk,項目名稱:GenesisH0,代碼行數:26,代碼來源:genesis.py

示例12: generate_hash

# 需要導入模塊: import scrypt [as 別名]
# 或者: from scrypt import hash [as 別名]
def generate_hash(data_block, algorithm, start_nonce, bits):
  print 'Searching for genesis hash..'
  nonce           = start_nonce
  last_updated    = time.time()
  # https://en.bitcoin.it/wiki/Difficulty
  target = (bits & 0xffffff) * 2**(8*((bits >> 24) - 3))

  while True:
    sha256_hash, header_hash = generate_hashes_from_block(data_block, algorithm)
    last_updated             = calculate_hashrate(nonce, last_updated)
    if is_genesis_hash(header_hash, target):
      if algorithm == "X11" or algorithm == "X13" or algorithm == "X15":
        return (header_hash, nonce)
      return (sha256_hash, nonce)
    else:
     nonce      = nonce + 1
     data_block = data_block[0:len(data_block) - 4] + struct.pack('<I', nonce) 
開發者ID:lhartikk,項目名稱:GenesisH0,代碼行數:19,代碼來源:genesis.py

示例13: generate_key

# 需要導入模塊: import scrypt [as 別名]
# 或者: from scrypt import hash [as 別名]
def generate_key(kdf_salt, password, iterations=16384, r=8, p=1, buflen=32):
        """Generates the key that is used for encryption/decryption"""

        secret_key = scrypt.hash(
            password, kdf_salt, N=iterations, r=r, p=p, buflen=buflen
        )
        return secret_key 
開發者ID:nutanix,項目名稱:calm-dsl,代碼行數:9,代碼來源:crypto.py

示例14: get_merkle_root

# 需要導入模塊: import scrypt [as 別名]
# 或者: from scrypt import hash [as 別名]
def get_merkle_root(transactions):
    branches = [t.hash for t in transactions]

    while len(branches) > 1:
        if (len(branches) % 2) == 1:
            branches.append(branches[-1])

        branches = [sha256d(a + b) for (a, b) in zip(branches[0::2], branches[1::2])]

    return branches[0]


# Hexlify Helpers 
開發者ID:ricmoo,項目名稱:pycoind,代碼行數:15,代碼來源:__init__.py

示例15: hash_password

# 需要導入模塊: import scrypt [as 別名]
# 或者: from scrypt import hash [as 別名]
def hash_password(password, salt):
    hashed = b85encode(shash(password, salt[:User.SALT_LENGTH]))
    return hashed.decode()[:User.PASSWORD_LENGTH] 
開發者ID:archlinux,項目名稱:arch-security-tracker,代碼行數:5,代碼來源:user.py


注:本文中的scrypt.hash方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。