如何使用 RSA-SHA1 为 oAuth 1.0 签名基本字符串?

问题描述

我正在尝试将旧的 Ruby oAuth1.0 客户端重构为 TypeScript。 (不幸的是,我目前无法将服务器升级到 oAuth2.0)。请求参数通过 RSA-SHA1 私有 RSA 密钥签名。

这是遗留的 Ruby 代码

@consumer = OAuth::Consumer.new(credentials[:consumer_key],credentials[:private_key],site: credentials[:base_uri],signature_method: 'RSA-SHA1')
token = OAuth::Accesstoken.new(@consumer,credentials[:access_token],credentials[:access_token_secret])

这是使用 https://github.com/rzcoder/node-rsa 的 TS 代码

编辑:在查看 the spec 后,我明确添加了密钥的类型 - pkcs1-private

const oauth = new OAuth({
        consumer,version: '1.0',signature_method: 'RSA-SHA1',hash_function: (baseString,key) => {
            const nPrivateKey = new NodeRSA(privateKey,'pkcs1-private');
            return nPrivateKey.encrypt(baseString,'base64');
        },})

这是PHP服务器验证码:

$decodedSignature = \base64_decode($request->urldecode($signature));
$certificate = $this->getPublicCertificate($request);
$publicKeyId = \openssl_get_publickey($certificate);
$isValid = \openssl_verify($baseString,$decodedSignature,$publicKeyId);

在服务器上调试时,OpenSSL 验证与公钥不匹配。

对于可能的编码组合、不同的密钥和算法,我不确定如何调试/测试。

有什么想法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)