auth/TokenHashUtil.java

mateclaw · mateclaw-server/src/main/java/vip/mate/kbopen/auth/TokenHashUtil.java · java · Apache-2.0
auth, tag:embed-classified

Spring component providing SHA‑256 hashing and random token generation for API keys.

// Source: https://github.com/mateaix/mateclaw | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
package vip.mate.kbopen.auth;

import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Base64;
import java.util.HexFormat;

/**
 * Shared token hash kernel (A4).
 *
 * <p>Generates cryptographically random token plaintext, computes its SHA-256
 * hash for storage, and verifies a plaintext against a stored hash. This is
 * the single source of truth for token hashing so that KB API Keys and (in a
 * future refactor) PAT 

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key