할 수 있는 방법을 강제로 기능을 해결하려면 보류 중인 약속에서 사용하기 전에 JavaScript
generateKey(pass, iter).then(function(result) {
Pkey = result;
});
위 Pkey 환 <empty string>
를 해결하기 전에 내가 쓸 수 있는 루프를 확인하 non-공허함이지만 하는 것이 어긋,no?
고
Pkey = generateKey(pass, iter);
반환하는 보류 중인 약속이 결국 성취
function generateKey(passwd, iterations) {
var encoder = new TextEncoder('utf-8');
var passphraseKey = encoder.encode(passwd);
var saltBuffer = encoder.encode("carthage");
return crypto.subtle.importKey(
'raw',
passphraseKey,
{name: 'PBKDF2'},
false,
['deriveBits', 'deriveKey']
).then(function(key) {
// console.log(key);
return window.crypto.subtle.deriveKey(
{ "name": 'PBKDF2',
"salt": saltBuffer,
"iterations": iterations,
"hash": 'SHA-256'
},
key,
{ "name": 'AES-CBC',
"length": 256
},
true,
[ "encrypt", "decrypt" ]
)
}).then(function (webKey) {
// console.log(webKey);
return crypto.subtle.exportKey("raw", webKey);
}).then(function (buffer) {
// console.log(buffer);
// console.log(saltBuffer);
// console.log("Private Key = " + buf2hex(buffer));
// console.log("Salt = " + bytesToHexString(saltBuffer));
return buffer;
});
}
function buf2hex(buffer) { // buffer is an ArrayBuffer
return Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join('');
}
function bytesToHexString(byteArray) {
return Array.prototype.map.call(byteArray, function(byte) {
return ('0' + (byte & 0xFF).toString(16)).slice(-2);
}).join('');
}
.then()
나await
을 얻을 해결에서 값을 약속 이 기능을 반환합니다.