From 5569055c17fdafaf3fb80a56aab37a6e2f42152c Mon Sep 17 00:00:00 2001 From: Muse Date: Tue, 20 Oct 2026 01:28:09 +0800 Subject: [PATCH] =?UTF-8?q?agent:=20Reality=20=E5=AF=86=E9=92=A5=20JWK=20b?= =?UTF-8?q?ase64url=20=E8=BD=AC=E6=A0=87=E5=87=86=20base64=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=20sing-box=20check=20=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agent/agent.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/agent/agent.js b/agent/agent.js index 05825ca..695bf9e 100644 --- a/agent/agent.js +++ b/agent/agent.js @@ -66,7 +66,9 @@ 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 密钥生成失败'); - keys[keyId] = { privateKey: priv.d, publicKey: pub.x, createdAt: new Date().toISOString() }; + // JWK 用 base64url,sing-box 要标准 base64,转换一下 + const b64urlToB64 = (s) => s.replace(/-/g, '+').replace(/_/g, '/') + '='.repeat((4 - s.length % 4) % 4); + keys[keyId] = { privateKey: b64urlToB64(priv.d), publicKey: b64urlToB64(pub.x), createdAt: new Date().toISOString() }; saveKeys(keys); return keys[keyId]; }