Encryption using cryptoaes algorithm

Hi,
Customer using cryptojs to encrypt the password and sending in API for mobile application.For same way ,they are expecting the password from the chatbot to pass into API’s.

I have tried to use cryptojs using ymLib but it’s not giving any output.

Code they are using at their end to encrypt the password:

var password = $(“#pass”).val(); // “userpassword
var secret = $(”#secret").val(); //customerId
var encrypted = CryptoJS.AES.encrypt(password, secret);
encrypted = encrypted.toString();
$(“#encPass”).text(encrypted);

console.log("Encrypted Value: " + encrypted);

They are using

On our platform how can we encrypted in same way? Can anyone suggest ?

Can you try using this code:-

return new Promise(resolve => {
    // Your logic goes here
    console.log("inside encrypting mobile number------>");
    let mobileNo = data.variables.phoneVar;
    console.log(mobileNo, "mobileNumber")

    let remove_91 = mobileNo;
    const withoutFirst2 = remove_91.slice(2);
    console.log(withoutFirst2, "without 91 in mobile number+++++++>>>>>>>>");

    let object = { "MobileNumber": withoutFirst2 }
    let obj = JSON.stringify(object, null, 2)
    console.log(obj, "obj======+++++++>>>>>");
    let enc_dec_key = 'z3qhDE1GC6Dgxk+PRtqw93tXPq3bY+O1SubwWp8Cd54=';
    console.log(enc_dec_key, 'encryption+++++======');
    function encryptAPIdata(data) {
        try {

            let cipher = ymLib.crypto.createCipheriv('aes-128-cbc', Buffer.from(enc_dec_key), enc_dec_key);
            let encrypted = cipher.update(data);
            encrypted = Buffer.concat([encrypted, cipher.final()]);
            return encrypted.toString('base64');
        } catch (err) {
            console.log(err, 'Error in  encryptAPIdata');
            throw new Error(err);
        }
    }


    let after_encryption_Mobilenumber = encryptAPIdata(obj);
    console.log(after_encryption_Mobilenumber, 'after mobile number is encrypted=====+++++');
    resolve(after_encryption_Mobilenumber);
});

here, I am encrypting phone number entered by the user using aes algorithm.

Hi @Sakshi_Mishra ,
I have tried to use your code,but getting error as ERR_CRYPTO_INVALID_IV .

@Aishwarya.Gandhi please confirm on the algorithm that is used. is it aes-128 or aes-256?

They are using this code to do encryption:
They are using plain aes algorithm
@Sakshi_Mishra
Scripts they are included
https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.js
https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js

$(document).ready(function(){

$(“#getpass”).click(function(){

var password = $(“#pass”).val(); // “userpassword
var secret = $(”#secret").val(); //customerId
var encrypted = CryptoJS.AES.encrypt(password, secret);
encrypted = encrypted.toString();
$(“#encPass”).text(encrypted);

console.log("Encrypted Value: " + encrypted);
});
});

Testing Times :- Get Encrypted Password Value :-
Login:-
Pass :-

----<