节点。jCryption 3.0服务器端部分的js实现。

时间:2022-03-01 16:09:00

Did anyone implement server-side part of jCryption 3.0 plugin with node.js? Author uses PHP for server, here's code on GitHub. I'm struggling with handshake handler, somehow I cannot decrypt request's base64 key with my private PEM key (I use 'ursa' module for RSA). Here's my handler (it's not completely finished in challenge part):

有没有人用node.js实现了jCryption 3.0插件的服务器端部分?作者使用PHP作为服务器,这是GitHub上的代码。我正在与握手处理程序作比较,我无法用我的私有PEM密钥来解密请求的base64密钥(我使用了RSA的ursa模块)。这是我的处理器(它还没有完全完成挑战部分):

var ursa = require('ursa');
...
// write public key to HTML with EJS 
exports.getPublicKeyMiddleware = function(req, res, next){
    res.publicKey = req.app.get('publicKey'); // stores result of readFile(PUBLIC_KEY.PEM)
    next();
};

exports.handshake = function(req, res, next) {
    var base64key = req.body.key;
    var privateKey;
    var challenge;

    if (!!base64key) {
        myPrivateKey = ursa.createPrivateKey(req.app.get('privateKey'));

        try {
            challenge = privateKey.decrypt(base64key, 'base64', 'utf8');
            res.json({challenge: challenge});

        }
        catch (e) {
            res.json({error: 'Error decoding key'});
            console.log(e.message);
        }

     }
     else {
        res.json({error: 'No key in request'})
     }
}

Now it's always an error when decrypt. Like this:

现在,当解密时,它总是一个错误。是这样的:

Error: error:0407A079:rsa routines:RSA_padding_check_PKCS1_OAEP:oaep decoding error

Can you please look at PHP workflow (link above) and point me what I am doing wrong maybe? Thanks

您能看看PHP工作流(上面的链接)并指出我做错了什么吗?谢谢

EDIT: Like HazA said padding was the case:

编辑:就像HazA说的填充是这样的:

myPrivateKey.decrypt(base64key, 'base64', 'utf8', ursa.RSA_PKCS1_PADDING);

1 个解决方案

#1


1  

Did you try using the other Padding

你试过用其他填充物吗?

RSA_PKCS1_PADDING instead of RSA_PKCS1_OAEP_PADDING

RSA_PKCS1_PADDING代替RSA_PKCS1_OAEP_PADDING

Like described in the documentation

就像文档中描述的那样。

https://github.com/Obvious/ursa#decryptbuf-bufencoding-outencoding-padding

https://github.com/Obvious/ursa decryptbuf-bufencoding-outencoding-padding

#1


1  

Did you try using the other Padding

你试过用其他填充物吗?

RSA_PKCS1_PADDING instead of RSA_PKCS1_OAEP_PADDING

RSA_PKCS1_PADDING代替RSA_PKCS1_OAEP_PADDING

Like described in the documentation

就像文档中描述的那样。

https://github.com/Obvious/ursa#decryptbuf-bufencoding-outencoding-padding

https://github.com/Obvious/ursa decryptbuf-bufencoding-outencoding-padding