def _calc_checksum_bcryptor(self, secret): #bcryptor behavior: # py2: unicode secret -> ascii bytes (we have to override) # unicode hash -> ascii bytes (we provide ascii bytes) # returns ascii bytes # py3: can't get to install if isinstance(secret, unicode): secret = secret.encode("utf-8") hash = bcryptor_engine(False).hash_key(secret, self.to_string(native=False)) return hash[-31:].decode("ascii")
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:])