【发布时间】:2021-05-25 04:12:41
【问题描述】:
标题不是最好的,因为听起来我想在 JS 中构建自己的 RSA 加密算法,但让我解释一下。
我想通过 Steam 服务器进行身份验证。向 2 个 url 发出 4 个帖子请求,此帖子的主 url 是 https://store.steampowered.com/login/getrsakey
它返回 3 个重要的东西,即 RSA 时间戳、模数和指数。我不会在这里发布数据,因为我不确定它是否包含任何重要但很容易获得的信息(在donotcache 下提供您的蒸汽用户名username 和Date.now() * 1000。将其添加到表单数据并制作一个POST 请求到 url)
我在github上找到了一个python script,它实现了登录steam。这是我要转换成 JS 的代码:
mod = long(str(data["publickey_mod"]), 16)
exp = long(str(data["publickey_exp"]), 16)
rsa = RSA.construct((mod, exp))
cipher = PKCS1_v1_5.new(rsa)
print base64.b64encode(cipher.encrypt(passwd))
它使用来自响应的数据来构造一个 RSA 密钥。从该密钥创建PKCS1_v1_5 密码,然后加密密码。我已经有了 NodeRSA,但由于某种原因它breaks within a promise。今天,我来到this 加密库,我在其中尝试了示例(rsa.sign 示例,因为我无法传入rsa.encrypt 的RSASSA-PKCS1-v1_5 名称)首先传入的是普通的publickey_mod 和@987654334 @来自网址但它出错了:
Error: UnsupportedEnvironment: Cannot create a key using the specified key usages.
我也试过了:
const n = Buffer.from(mod, "hex");
const e = Buffer.from(exp, 0);
我从 NodeRSA 示例中得到的。这也有错误:
Error: UnsupportedEnvironment: The JWK member "n" could not be base64url decoded or contained padding
事实证明,加密这个密码非常困难,我想知道是否有人可以提供一些帮助?
【问题讨论】:
标签: javascript python encryption rsa