The AesCrypto.encrypt()
is asynchronous, which means that if you want to return the value of a
from your encrypt()
function using the structure you've defined above, then you'll need to define it as an asynchronous function like so:
/* Declare the function as asynchronous with async keyword */
function async encrypt(plaintxt){
const secretKey = '124567980123456';
const iv = "1234567890123456";
/* Create a promoise and wait for it to complete (or fail)
using the await keyword */
const a = await (new Promise((resolve, reject) => {
/* Resolve or reject the promise by passing the handlers
to your promise handlers */
AesCrypto.encrypt(plaintxt,secretKey,iv)
.then(resolve)
.catch(reject);
}))
return a;
}