Class CaptchaSecurity
java.lang.Object
cloud.opencode.base.captcha.security.CaptchaSecurity
Captcha Security - Security utilities for CAPTCHA
验证码安全 - 验证码安全工具
This class provides security-related utilities for CAPTCHA operations.
此类提供验证码操作的安全相关工具。
Features | 主要功能:
- Secure random ID generation - 安全随机ID生成
- Hash-based answer comparison - 基于哈希的答案比较
- Timing-safe comparison - 时间安全的比较
Usage Examples | 使用示例:
String id = CaptchaSecurity.generateId();
String hash = CaptchaSecurity.hashAnswer("abc123");
boolean match = CaptchaSecurity.verifyAnswer(hash, "abc123");
Security | 安全性:
- Thread-safe: Yes (stateless utility, uses static SecureRandom) - 线程安全: 是(无状态工具,使用静态SecureRandom)
- Null-safe: No (arguments must not be null) - 空值安全: 否(参数不能为null)
- Since:
- JDK 25, opencode-base-captcha V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanconstantTimeEquals(String a, String b) Constant-time string comparison to prevent timing attacks.static StringGenerates a random salt.static StringGenerates a secure random ID.static StringgenerateSecureToken(int length) Generates a secure random token.static StringhashAnswer(String answer, String salt) Hashes an answer for secure storage.static booleanverifyHashedAnswer(String answer, String hashedAnswer, String salt) Verifies a hashed answer.
-
Method Details
-
generateSecureId
Generates a secure random ID. 生成安全随机 ID。- Returns:
- the random ID | 随机 ID
-
generateSecureToken
Generates a secure random token. 生成安全随机令牌。- Parameters:
length- the token length in bytes | 令牌字节长度- Returns:
- the random token | 随机令牌
-
hashAnswer
-
verifyHashedAnswer
-
constantTimeEquals
-
generateSalt
-