Compare commits
2 Commits
d36d66bbf7
...
8c8c98b756
| Author | SHA1 | Date | |
|---|---|---|---|
| 8c8c98b756 | |||
| 2ec41eb3a5 |
@@ -1,5 +1,7 @@
|
|||||||
package crypto
|
package crypto
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
// Encryptor 加密器接口
|
// Encryptor 加密器接口
|
||||||
type Encryptor interface {
|
type Encryptor interface {
|
||||||
// Encrypt 加密数据
|
// Encrypt 加密数据
|
||||||
@@ -20,3 +22,27 @@ type Signer interface {
|
|||||||
// Verify 验证签名
|
// Verify 验证签名
|
||||||
Verify(data, signature []byte) error
|
Verify(data, signature []byte) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
SecretKey string // 对称加密密钥
|
||||||
|
SignKey string // 签名密钥
|
||||||
|
TimestampWindow time.Duration // 时间戳允许的时间窗口
|
||||||
|
EnableTimestamp bool // 是否启用时间戳验证
|
||||||
|
EnableSignature bool // 是否启用签名
|
||||||
|
}
|
||||||
|
|
||||||
|
type EncryptedRequest struct {
|
||||||
|
Data string `json:"data"` // 加密后的数据(Base64)
|
||||||
|
Signature string `json:"signature"` // 签名(Base64)
|
||||||
|
Timestamp int64 `json:"timestamp"` // 时间戳
|
||||||
|
RequestID string `json:"request_id"` // 请求ID
|
||||||
|
Algorithm string `json:"algorithm"` // 加密算法
|
||||||
|
}
|
||||||
|
|
||||||
|
// EncryptedResponse 加密响应体
|
||||||
|
type EncryptedResponse struct {
|
||||||
|
Data string `json:"data"`
|
||||||
|
Signature string `json:"signature"`
|
||||||
|
Timestamp int64 `json:"timestamp"`
|
||||||
|
RequestID string `json:"request_id"`
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user