From 0b180fe7cc1be0ea62b5e18865a3336d5bd1b490 Mon Sep 17 00:00:00 2001 From: Muse Date: Tue, 20 Oct 2026 01:44:21 +0800 Subject: [PATCH] =?UTF-8?q?agent:=20=E7=94=A8=20Buffer=20=E5=81=9A=20base6?= =?UTF-8?q?4url=20=E8=BD=AC=20base64=EF=BC=8C=E4=BF=AE=E5=A1=AB=E5=85=85?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agent/agent.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agent/agent.js b/agent/agent.js index 695bf9e..4f794f0 100644 --- a/agent/agent.js +++ b/agent/agent.js @@ -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];