Files
base-golang/pkg/crypto/client/crypto/interface.ts
2026-02-07 15:38:01 +08:00

51 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 加密器接口
*/
export interface IEncryptor {
encrypt(plaintext: Uint8Array): Promise<Uint8Array>;
decrypt(ciphertext: Uint8Array): Promise<Uint8Array>;
name(): string;
}
/**
* 签名器接口
*/
export interface ISigner {
sign(data: Uint8Array): Promise<Uint8Array>;
verify(data: Uint8Array, signature: Uint8Array): Promise<boolean>;
}
/**
* 配置选项
*/
export interface CryptoConfig {
secretKey?: string; // 对称加密密钥
signKey?: string; // 签名密钥
publicKey?: string; // RSA公钥PEM格式
privateKey?: string; // RSA私钥PEM格式
timestampWindow?: number; // 时间戳窗口(毫秒)
enableTimestamp?: boolean; // 是否启用时间戳验证
enableSignature?: boolean; // 是否启用签名
}
/**
* 加密请求体
*/
export interface EncryptedRequest {
data: string; // Base64编码的加密数据
signature?: string; // Base64编码的签名
timestamp: number; // 时间戳
request_id: string; // 请求ID
algorithm: string; // 加密算法名称
}
/**
* 加密响应体
*/
export interface EncryptedResponse {
data: string; // Base64编码的加密数据
signature?: string; // Base64编码的签名
timestamp: number; // 时间戳
request_id: string; // 请求ID
}