@@ -14,17 +14,14 @@ export class DeriveProvider {
14
14
} ) : Promise < Buffer > {
15
15
const keyPath = `/${ params . agentId } /tee/keypair/${ params . bizModel } ` ;
16
16
const seed = await this . provider . rawDeriveKey ( keyPath , params . agentId ) ;
17
- // 从 PEM 格式解析私钥
18
17
const privateKey = crypto . createPrivateKey ( {
19
18
key : seed . key ,
20
19
format : "pem" ,
21
20
} ) ;
22
- // 导出私钥为 DER 格式
23
21
const privateKeyDer = privateKey . export ( {
24
22
format : "der" ,
25
23
type : "pkcs8" ,
26
24
} ) ;
27
- // 使用 SHA-256 对私钥进行哈希,派生出对称加密密钥
28
25
return crypto . createHash ( "sha256" ) . update ( privateKeyDer ) . digest ( ) ;
29
26
}
30
27
@@ -89,26 +86,23 @@ export class DeriveProvider {
89
86
}
90
87
}
91
88
92
- // 加密函数
93
89
private encrypt (
94
90
text : string ,
95
91
key : Buffer
96
92
) : { ivHex : string ; encrypted : string } {
97
- // 生成随机初始化向量(IV)
93
+ // generate a random initialization vector iv
98
94
const iv = crypto . randomBytes ( 16 ) ;
99
95
100
- // 创建 cipher 对象
96
+ // create cipher object
101
97
const cipher = crypto . createCipheriv ( "aes-256-cbc" , key , iv ) ;
102
98
103
- // 加密
104
99
let encrypted = cipher . update ( text , "utf8" , "hex" ) ;
105
100
encrypted += cipher . final ( "hex" ) ;
106
101
107
- // 返回 IV 和加密后的数据( IV 需要在解密时使用)
102
+ //Return IV and encrypted data ( IV needs to be used during decryption)
108
103
return { ivHex : iv . toString ( "hex" ) , encrypted : encrypted } ;
109
104
}
110
105
111
- // 解密函数
112
106
private decrypt ( encryptedData : string , ivHex : string , key : Buffer ) : string {
113
107
const decipher = crypto . createDecipheriv (
114
108
"aes-256-cbc" ,
0 commit comments