Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

Encryption node Js

General Tech Bugs & Fixes

Max. 2000 characters
Replies

usr_profile.png

User

( 6 months ago )

Hi this is my encryption code i'm trying to decrypt the code in Android via json. I can decrypt this code in node js. But when i tried to decrypt in android error occured so any one suggest me where the problem is occur whether in my node js code or android.

app.post('/insert',  function (req,res){
        var data = {
            userId:req.body.fname,
            firstName:req.body.fname
        };


                var cipher = crypto.createCipher('aes128', 'a password');
                 data.firstName = cipher.update(data.firstName, 'utf8','base64' );
                data.firstName += cipher.final('base64');
                console.log(data);

         con.query("insert into md5 set ?",[data], function (err,rows){
            if(err) throw err;  
                res.send("Value has been inserted");
            })
             console.log(data.firstName);
        })

usr_profile.png

User

( 6 months ago )

 

When we are using any kind of Encryption and Decryption into our System (Including DB) our all clients should be having similar credentials to parsing that message.

Lets say we have Backend, Web and Mobile Apps(Android/iPhone). So what backend Encrypt the message with whatever credentials All other client can be having same credentials to decrypt that message.

Here i am suggesting that AES Use 256 with Predefine IV and KEY. And Crypto is very famous library that will having the feature in all the platform. I did with Node.js.

Snippet for Encrypt Text:

encryptText: function(text) {
        var cipher = crypto.createCipheriv(Constant.algo, Constant.key, Constant.iv);
        var result = cipher.update(text, "utf8", 'base64');
        result += cipher.final('base64');
        return result;
    },

Snippet for Decrypt Text:

decryptText: function(text) {
        console.log(text);

        var decipher = crypto.createDecipheriv(Constant.algo, Constant.key, Constant.iv);
        var result = decipher.update(text, 'base64');
        result += decipher.final();
        return result;
    },

what's your interest


forum_ban8_5d8c5fd7cf6f7.gif