Class SignedEvent
java.lang.Object
cloud.opencode.base.event.Event
cloud.opencode.base.event.security.SignedEvent
- All Implemented Interfaces:
VerifiableEvent
Signed Event Base Class
签名事件基类
Abstract base class for events that include cryptographic signatures.
包含加密签名的事件的抽象基类。
Features | 主要功能:
- HMAC-SHA256 signature - HMAC-SHA256签名
- Automatic signing on creation - 创建时自动签名
- Signature verification - 签名验证
Usage Examples | 使用示例:
public class SecureOrderEvent extends SignedEvent {
private final Order order;
public SecureOrderEvent(Order order, String secret) {
super(secret);
this.order = order;
}
@Override
protected String getPayload() {
return order.getId().toString();
}
}
// Create and verify
SecureOrderEvent event = new SecureOrderEvent(order, secretKey);
if (event.verify(secretKey)) {
// Event is authentic
}
Security | 安全性:
- Thread-safe: No - 线程安全: 否
- Since:
- JDK 25, opencode-base-event V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSignedEvent(String secret) Create signed event with automatic signing 使用自动签名创建签名事件protectedSignedEvent(String source, String secret) Create signed event with source and automatic signing 使用来源和自动签名创建签名事件 -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract StringGet the payload data for signing 获取用于签名的负载数据Get the event signature 获取事件签名booleanVerify the event signature 验证事件签名Methods inherited from class Event
cancel, getId, getSource, getTimestamp, isCancelled, toString
-
Constructor Details
-
SignedEvent
Create signed event with automatic signing 使用自动签名创建签名事件- Parameters:
secret- the secret key for signing | 用于签名的密钥
-
SignedEvent
-
-
Method Details
-
getPayload
Get the payload data for signing 获取用于签名的负载数据Subclasses must implement this method to provide the data that should be included in the signature.
子类必须实现此方法以提供应包含在签名中的数据。
- Returns:
- the payload string | 负载字符串
-
getSignature
Description copied from interface:VerifiableEventGet the event signature 获取事件签名- Specified by:
getSignaturein interfaceVerifiableEvent- Returns:
- the signature string | 签名字符串
-
verify
Description copied from interface:VerifiableEventVerify the event signature 验证事件签名- Specified by:
verifyin interfaceVerifiableEvent- Parameters:
secret- the secret key used for verification | 用于验证的密钥- Returns:
- true if signature is valid | 如果签名有效返回true
-