函数decrypt返回的是一个Promise对象,console.log(getResult())打印出来是Promise {pending},请问怎样才能通过getResult()从这个对象中获取它的返回值?打印getResult()出来是返回值,而不是Promise {pending}?
const crypto = require('crypto');
function d(e) {
for (var t = (e + "=".repeat((4 - e.length % 4) % 4)).replace(/\-/g, "+").replace(/_/g, "/"), n = atob(t), r = new Uint8Array(n.length), i = 0; i < n.length; i++)
r[i] = n.charCodeAt(i);
return r
}
var text = "X6sYd0tUg+4EP1CeOBKrSK7S53ojwM5pjhdMXn/ET0LF6cjZyKF1YRxNw5XPgq9lQ0jEr2hOCDNTTfFby1Xh/2rAvobvsakg6W21LkNlUYHez1yHDxaQp1+7CxmjBuN6";
var key = "kbSjOqn9O7APLqUZxdCkTQ==";
var iv = "JuhL1cOV5JH9ojzt2g2EPg==";
async function decrypt(text,key,iv) {
var l ="AES-CBC";
var t = d(key);
var i = d(iv);
var r = await crypto.webcrypto.subtle.importKey("raw", t, l, !0, ["decrypt"]);
var result = await crypto.webcrypto.subtle.decrypt({
name: l,
iv: i
}, r, d(text));
result = (new TextDecoder()).decode(result)
return result
}
function getResult(){
var p = decrypt(text,key,iv);
return Promise.all([p]).then(data=>{
console.log(data[0])
return data[0]
})
}
console.log(getResult()) // 输出 Promise {pending}