Skip to content

Commit 5dfbaaa

Browse files
committed
feat: fix log
1 parent d13590b commit 5dfbaaa

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

packages/plugin-tee-verifiable-log/src/providers/dreriveProvider.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@ export class DeriveProvider {
1414
}): Promise<Buffer> {
1515
const keyPath = `/${params.agentId}/tee/keypair/${params.bizModel}`;
1616
const seed = await this.provider.rawDeriveKey(keyPath, params.agentId);
17-
// 从 PEM 格式解析私钥
1817
const privateKey = crypto.createPrivateKey({
1918
key: seed.key,
2019
format: "pem",
2120
});
22-
// 导出私钥为 DER 格式
2321
const privateKeyDer = privateKey.export({
2422
format: "der",
2523
type: "pkcs8",
2624
});
27-
// 使用 SHA-256 对私钥进行哈希,派生出对称加密密钥
2825
return crypto.createHash("sha256").update(privateKeyDer).digest();
2926
}
3027

@@ -89,26 +86,23 @@ export class DeriveProvider {
8986
}
9087
}
9188

92-
// 加密函数
9389
private encrypt(
9490
text: string,
9591
key: Buffer
9692
): { ivHex: string; encrypted: string } {
97-
// 生成随机初始化向量(IV)
93+
// generate a random initialization vector iv
9894
const iv = crypto.randomBytes(16);
9995

100-
// 创建 cipher 对象
96+
// create cipher object
10197
const cipher = crypto.createCipheriv("aes-256-cbc", key, iv);
10298

103-
// 加密
10499
let encrypted = cipher.update(text, "utf8", "hex");
105100
encrypted += cipher.final("hex");
106101

107-
// 返回 IV 和加密后的数据(IV 需要在解密时使用)
102+
//Return IV and encrypted data (IV needs to be used during decryption)
108103
return { ivHex: iv.toString("hex"), encrypted: encrypted };
109104
}
110105

111-
// 解密函数
112106
private decrypt(encryptedData: string, ivHex: string, key: Buffer): string {
113107
const decipher = crypto.createDecipheriv(
114108
"aes-256-cbc",

0 commit comments

Comments
 (0)