Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

While the text is greater then 14 characters the decrypt do not works #62

Open
kapil303196 opened this issue Jun 15, 2020 · 2 comments
Open
Labels

Comments

@kapil303196
Copy link

router.post('/api/test', (req, res) => {
    try {
        var privateKeyB = eccrypto.generatePrivate();
        var publicKeyB = eccrypto.getPublic(privateKeyB);
        console.log("body data",req.body)
        let body = JSON.parse(JSON.stringify(req.body))
        console.log(body)
        // Encrypting the message for B.
        eccrypto.encrypt(publicKeyB, Buffer.from(body.data)).then((encrypted) => {
            eccrypto.decrypt(privateKeyB, encrypted).then(function(plaintext) {
                console.log("Message to part B:", plaintext.toString());
                res.json({"msg": plaintext.toString()})
            }).catch((e) => {
                console.log("err while decrypting ",e)
                res.statusCode(400).send(e)
            });
        }).catch((e) => {
            console.log("err while encrypting ",e)
            res.statusCode(400).send(e)
        });
    } catch (error) {
        console.log("error try catch",error);
        res.statusCode(400).send(error)
    }
})

while my req.body.data parameter length is greater then 14 its breaking.

@dungcui
Copy link

dungcui commented Jun 17, 2020

body.data is an object, you should use Buffer.from with a string like JSON.stringify(body.data)

@JBaczuk
Copy link
Contributor

JBaczuk commented Jun 17, 2020

I'm not able to reproduce, can you share any more info about your environment and setup?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants