def _calc_checksum(self, secret): if isinstance(secret, unicode): secret = secret.encode("utf-8") if not hasattr(self, "salt_fn"): raise RuntimeError("No salt function specified for DataZoomerSaltedHash") salt = callable(self.salt_fn) and self.salt_fn() or self.salt_fn return str_to_uascii(sha1(sha1(salt.encode("ascii") + secret).digest()).hexdigest()).upper()
def _calc_checksum(self, secret, digestmod=None): if isinstance(secret, unicode): secret = secret.encode('utf-8') if isinstance(self.salt, unicode): self.salt = self.salt.encode('utf-8') # return hmac.new(self.salt, secret, digestmod).hexdigest() return str_to_uascii(hmac.new(self.salt, secret, digestmod).hexdigest())
def _calc_checksum_bcryptor(self, secret, config): # bcryptor behavior: # py2: unicode secret/hash encoded as ascii bytes before use, # bytes taken as-is; returns ascii bytes. # py3: not supported hash = _bcryptor.engine.Engine(False).hash_key(secret, config) assert hash.startswith(config) and len(hash) == len(config)+31 return str_to_uascii(hash[-31:])
def _calc_checksum(self, secret): """Calculate string. :param secret: The secret key. :returns: The checksum. """ return str_to_uascii( hashlib.sha256(mysql_aes_encrypt(self.salt, secret)).hexdigest())
def _calc_checksum_pybcrypt(self, secret, config): # py-bcrypt behavior: # py2: unicode secret/hash encoded as ascii bytes before use, # bytes taken as-is; returns ascii bytes. # py3: unicode secret encoded as utf-8 bytes, # hash encoded as ascii bytes, returns ascii unicode. hash = _bcrypt.hashpw(secret, config) assert hash.startswith(config) and len(hash) == len(config)+31 return str_to_uascii(hash[-31:])
def _calc_checksum(self, secret): # bcryptor behavior: # py2: unicode secret/hash encoded as ascii bytes before use, # bytes taken as-is; returns ascii bytes. # py3: not supported secret, ident = self._prepare_digest_args(secret) config = self._get_config(ident) hash = _bcryptor.engine.Engine(False).hash_key(secret, config) assert hash.startswith(config) and len(hash) == len(config)+31 return str_to_uascii(hash[-31:])
def _calc_checksum(self, secret): # bcryptor behavior: # py2: unicode secret/hash encoded as ascii bytes before use, # bytes taken as-is; returns ascii bytes. # py3: not supported secret, ident = self._prepare_digest_args(secret) config = self._get_config(ident) hash = _bcryptor.engine.Engine(False).hash_key(secret, config) assert hash.startswith(config) and len(hash) == len(config) + 31 return str_to_uascii(hash[-31:])
def _calc_checksum_raw(self, secret): # py-bcrypt behavior: # py2: unicode secret/hash encoded as ascii bytes before use, # bytes taken as-is; returns ascii bytes. # py3: unicode secret encoded as utf-8 bytes, # hash encoded as ascii bytes, returns ascii unicode. secret, ident = self._prepare_digest_args(secret) config = self._get_config(ident) hash = _pybcrypt.hashpw(secret, config) assert hash.startswith(config) and len(hash) == len(config)+31 return str_to_uascii(hash[-31:])
def _calc_checksum_raw(self, secret): # py-bcrypt behavior: # py2: unicode secret/hash encoded as ascii bytes before use, # bytes taken as-is; returns ascii bytes. # py3: unicode secret encoded as utf-8 bytes, # hash encoded as ascii bytes, returns ascii unicode. secret, ident = self._prepare_digest_args(secret) config = self._get_config(ident) hash = _pybcrypt.hashpw(secret, config) assert hash.startswith(config) and len(hash) == len(config) + 31 return str_to_uascii(hash[-31:])
def _calc_checksum_pybcrypt(self, secret): # py-bcrypt behavior: # py2: unicode secret/hash encoded as ascii bytes before use, # bytes taken as-is; returns ascii bytes. # py3: not supported (patch submitted) if isinstance(secret, unicode): secret = secret.encode("utf-8") if _BNULL in secret: raise uh.exc.NullPasswordError(self) config = self._get_config() hash = pybcrypt_hashpw(secret, config) assert hash.startswith(config) and len(hash) == len(config) + 31 return str_to_uascii(hash[-31:])
def _calc_checksum_pybcrypt(self, secret): # py-bcrypt behavior: # py2: unicode secret/hash encoded as ascii bytes before use, # bytes taken as-is; returns ascii bytes. # py3: not supported (patch submitted) if isinstance(secret, unicode): secret = secret.encode("utf-8") if _BNULL in secret: raise uh.exc.NullPasswordError(self) config = self._get_config() hash = pybcrypt_hashpw(secret, config) assert hash.startswith(config) and len(hash) == len(config)+31 return str_to_uascii(hash[-31:])
def _calc_checksum(self, secret): if isinstance(secret, unicode): secret = secret.encode("utf-8") if not hasattr(self, "salt_fn"): raise RuntimeError("No salt function specified for DataZoomerSaltedHash") weak_dz_salt = callable(self.salt_fn) and self.salt_fn() or self.salt_fn dz_hash = '*' + str_to_uascii(sha1(sha1(weak_dz_salt.encode("ascii") + secret).digest()).hexdigest()).upper() # NOTE: can't use digest directly, since bcrypt stops at first NULL. # NOTE: bcrypt doesn't fully mix entropy for bytes 55-72 of password # (XXX: citation needed), so we don't want key to be > 55 bytes. # thus, have to use base64 (44 bytes) rather than hex (64 bytes). key = b64encode(sha256(dz_hash).digest()) return self._calc_checksum_backend(key)
def _calc_checksum(self, secret): # NOTE: this bypasses bcrypt's _calc_checksum, # so has to take care of all it's issues, such as secret encoding. if isinstance(secret, unicode): secret = secret.encode("utf-8") # generate the mysql41 hash first (as it would be in the db mysql41_hash = '*' + str_to_uascii(sha1(sha1(secret).digest()).hexdigest()).upper() # NOTE: can't use digest directly, since bcrypt stops at first NULL. # NOTE: bcrypt doesn't fully mix entropy for bytes 55-72 of password # (XXX: citation needed), so we don't want key to be > 55 bytes. # thus, have to use base64 (44 bytes) rather than hex (64 bytes). key = b64encode(sha256(mysql41_hash).digest()) return self._calc_checksum_backend(key)
def _calc_checksum_bcryptor(self, secret): # bcryptor behavior: # py2: unicode secret/hash encoded as ascii bytes before use, # bytes taken as-is; returns ascii bytes. # py3: not supported if self.ident == IDENT_2: # bcryptor doesn't support $2$ hashes; but we can fake $2$ behavior # using the $2a$ algorithm, by repeating the password until # it's at least 72 chars in length. if secret: secret = repeat_string(secret, 72) config = self._get_config(IDENT_2A) else: config = self._get_config() hash = _bcryptor_engine(False).hash_key(secret, config) assert hash.startswith(config) and len(hash) == len(config) + 31 return str_to_uascii(hash[-31:])
def _calc_checksum_bcryptor(self, secret): # bcryptor behavior: # py2: unicode secret/hash encoded as ascii bytes before use, # bytes taken as-is; returns ascii bytes. # py3: not supported if self.ident == IDENT_2: # bcryptor doesn't support $2$ hashes; but we can fake $2$ behavior # using the $2a$ algorithm, by repeating the password until # it's at least 72 chars in length. if secret: secret = repeat_string(secret, 72) config = self._get_config(IDENT_2A) else: config = self._get_config() hash = _bcryptor_engine(False).hash_key(secret, config) assert hash.startswith(config) and len(hash) == len(config)+31 return str_to_uascii(hash[-31:])
def _calc_checksum_bcryptor(self, secret): # bcryptor behavior: # py2: unicode secret/hash encoded as ascii bytes before use, # bytes taken as-is; returns ascii bytes. # py3: not supported if isinstance(secret, unicode): secret = secret.encode("utf-8") if _BNULL in secret: # NOTE: especially important to forbid NULLs for bcryptor, # since it happily accepts them, and then silently truncates # the password at first one it encounters :( raise uh.exc.NullPasswordError(self) if self.ident == IDENT_2: # bcryptor doesn't support $2$ hashes; but we can fake $2$ behavior # using the $2a$ algorithm, by repeating the password until # it's at least 72 chars in length. if secret: secret = repeat_string(secret, 72) config = self._get_config(IDENT_2A) else: config = self._get_config() hash = bcryptor_engine(False).hash_key(secret, config) assert hash.startswith(config) and len(hash) == len(config) + 31 return str_to_uascii(hash[-31:])
def _calc_checksum_bcryptor(self, secret): # bcryptor behavior: # py2: unicode secret/hash encoded as ascii bytes before use, # bytes taken as-is; returns ascii bytes. # py3: not supported if isinstance(secret, unicode): secret = secret.encode("utf-8") if _BNULL in secret: # NOTE: especially important to forbid NULLs for bcryptor, # since it happily accepts them, and then silently truncates # the password at first one it encounters :( raise uh.exc.NullPasswordError(self) if self.ident == IDENT_2: # bcryptor doesn't support $2$ hashes; but we can fake $2$ behavior # using the $2a$ algorithm, by repeating the password until # it's at least 72 chars in length. if secret: secret = repeat_string(secret, 72) config = self._get_config(IDENT_2A) else: config = self._get_config() hash = bcryptor_engine(False).hash_key(secret, config) assert hash.startswith(config) and len(hash) == len(config)+31 return str_to_uascii(hash[-31:])
def _calc_checksum(self, secret): if isinstance(secret, unicode): secret = secret.encode("utf-8") user = to_bytes(self.user, "utf-8", param="user") return str_to_uascii(md5(secret + user).hexdigest())
def _calc_checksum(self, secret): if isinstance(secret, unicode): secret = secret.encode("utf-8") return str_to_uascii( md5(self.salt.encode("ascii") + secret).hexdigest())
def _calc_checksum(self, secret): if isinstance(secret, unicode): secret = secret.encode("utf-8") return str_to_uascii(self._hash_func(secret).hexdigest())
def _calc_checksum(self, secret): if isinstance(secret, unicode): secret = secret.encode("utf-8") data = self.salt.encode("ascii") + secret + self.salt.encode("ascii") return str_to_uascii(hashlib.sha1(data).hexdigest())
def _calc_checksum(self, secret): if isinstance(secret, unicode): secret = secret.encode("utf-8") data = b"boblious" + secret return str_to_uascii(hashlib.sha1(data).hexdigest())
def _calc_checksum(self, secret): """Calculate string.""" return str_to_uascii( hashlib.sha256(mysql_aes_encrypt(self.user, secret)).hexdigest() )
def _calc_checksum(self, secret): """Calculate string.""" return str_to_uascii( hashlib.sha256(mysql_aes_encrypt(self.user, secret)).hexdigest())
def _calc_checksum(self, secret): if isinstance(secret, unicode): secret = secret.encode("utf-8") chk = sha1(secret + unhexlify(self.salt.encode("ascii"))).hexdigest() return str_to_uascii(chk).upper()
def _calc_checksum(self, secret): m_salt = b64decode(self.salt).decode('utf-8') m_hash = sha1(m_salt + sha1(secret.encode('utf-8')).digest()) return str_to_uascii(m_hash.hexdigest())
def _calc_checksum(self, secret): if isinstance(secret, unicode): secret = secret.encode("utf-8") return str_to_uascii(md5(self.salt.encode("ascii") + secret).hexdigest())
def _calc_checksum(self, secret): # FIXME: no idea if mysql has a policy about handling unicode passwords if isinstance(secret, unicode): secret = secret.encode("utf-8") return str_to_uascii(sha1(sha1(secret).digest()).hexdigest()).upper()
def _calc_checksum(self, secret): m_str = secret + b64decode(self.salt).decode('utf-8') m_hash = sha256(m_str.encode('utf-8')) return str_to_uascii(m_hash.hexdigest())