@classmethod
def hash(cls, hash_cls, key, data, **kwargs):
    """Return hash of data from byte string or unicode string."""
    if isinstance(data, str):
        data = data.encode('utf-8')
    ctx = cls(hash_cls, key, **kwargs)
    ctx.update(data)
    return ctx.finalize()
