def to_string(self, withchk=True): salt = adapted_b64_encode(self.salt).decode("ascii") if withchk and self.checksum: chk = adapted_b64_encode(self.checksum).decode("ascii") hash = u'%s%d$%s$%s' % (self.ident, self.rounds, salt, chk) else: hash = u'%s%d$%s' % (self.ident, self.rounds, salt) return to_hash_str(hash)
def calc_checksum(self, secret): if isinstance(secret, unicode): secret = secret.encode("utf-8") salt = self.to_string(withchk=False, native=False).encode("ascii") result = pbkdf2(secret, salt, self.rounds, 24, "hmac-sha1") return adapted_b64_encode(result).decode("ascii")