agent: 用 Buffer 做 base64url 转 base64,修填充错误

This commit is contained in:
Muse
2026-10-20 01:44:21 +08:00
parent 693bb959ce
commit 0b180fe7cc
+2 -2
View File
@@ -66,8 +66,8 @@ function realityKey(keyId) {
const priv = kp.privateKey.export({ format: 'jwk' });
const pub = kp.publicKey.export({ format: 'jwk' });
if (!priv.d || !pub.x) throw new Error('X25519 密钥生成失败');
// JWK 用 base64url,sing-box 要标准 base64,转换一下
const b64urlToB64 = (s) => s.replace(/-/g, '+').replace(/_/g, '/') + '='.repeat((4 - s.length % 4) % 4);
// JWK 用 base64url,sing-box 要标准 base64,用 Buffer 转
const b64urlToB64 = (s) => Buffer.from(s, 'base64url').toString('base64');
keys[keyId] = { privateKey: b64urlToB64(priv.d), publicKey: b64urlToB64(pub.x), createdAt: new Date().toISOString() };
saveKeys(keys);
return keys[keyId];