convert crypto.subtle.deriveKey result to hex string
up vote
0
down vote
favorite
according to bip39 standard, I want to get seed from mnemonic words in javascript.
I use this code:
function mnemonicToSeed(mnemonic,passphrase){
if (typeof passphrase != 'string') passphrase='';
window.crypto.subtle.importKey(
'raw',
stringToArrayBuffer(mnemonic),
{
name: 'PBKDF2',
},
false,
['deriveKey']
).then((importedKey) => {
crypto.subtle.deriveKey({
name: "PBKDF2",
salt: stringToArrayBuffer('mnemonic'+passphrase),
iterations: 2048,
hash: { name: 'SHA-512' }
},
importedKey,
{
name: 'HMAC',
hash: 'SHA-512',
length: 512
},
true,
['sign']
).then(function(derivedKey) {
console.log('derivedKey: '+derivedKey);
});
});
}
but at last result of console.log('derivedKey: '+derivedKey);
is this:
derivedKey: [object CryptoKey]
now how convert derivedKey to its corresponding seed as hex string ?
javascript cryptography
add a comment |
up vote
0
down vote
favorite
according to bip39 standard, I want to get seed from mnemonic words in javascript.
I use this code:
function mnemonicToSeed(mnemonic,passphrase){
if (typeof passphrase != 'string') passphrase='';
window.crypto.subtle.importKey(
'raw',
stringToArrayBuffer(mnemonic),
{
name: 'PBKDF2',
},
false,
['deriveKey']
).then((importedKey) => {
crypto.subtle.deriveKey({
name: "PBKDF2",
salt: stringToArrayBuffer('mnemonic'+passphrase),
iterations: 2048,
hash: { name: 'SHA-512' }
},
importedKey,
{
name: 'HMAC',
hash: 'SHA-512',
length: 512
},
true,
['sign']
).then(function(derivedKey) {
console.log('derivedKey: '+derivedKey);
});
});
}
but at last result of console.log('derivedKey: '+derivedKey);
is this:
derivedKey: [object CryptoKey]
now how convert derivedKey to its corresponding seed as hex string ?
javascript cryptography
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
according to bip39 standard, I want to get seed from mnemonic words in javascript.
I use this code:
function mnemonicToSeed(mnemonic,passphrase){
if (typeof passphrase != 'string') passphrase='';
window.crypto.subtle.importKey(
'raw',
stringToArrayBuffer(mnemonic),
{
name: 'PBKDF2',
},
false,
['deriveKey']
).then((importedKey) => {
crypto.subtle.deriveKey({
name: "PBKDF2",
salt: stringToArrayBuffer('mnemonic'+passphrase),
iterations: 2048,
hash: { name: 'SHA-512' }
},
importedKey,
{
name: 'HMAC',
hash: 'SHA-512',
length: 512
},
true,
['sign']
).then(function(derivedKey) {
console.log('derivedKey: '+derivedKey);
});
});
}
but at last result of console.log('derivedKey: '+derivedKey);
is this:
derivedKey: [object CryptoKey]
now how convert derivedKey to its corresponding seed as hex string ?
javascript cryptography
according to bip39 standard, I want to get seed from mnemonic words in javascript.
I use this code:
function mnemonicToSeed(mnemonic,passphrase){
if (typeof passphrase != 'string') passphrase='';
window.crypto.subtle.importKey(
'raw',
stringToArrayBuffer(mnemonic),
{
name: 'PBKDF2',
},
false,
['deriveKey']
).then((importedKey) => {
crypto.subtle.deriveKey({
name: "PBKDF2",
salt: stringToArrayBuffer('mnemonic'+passphrase),
iterations: 2048,
hash: { name: 'SHA-512' }
},
importedKey,
{
name: 'HMAC',
hash: 'SHA-512',
length: 512
},
true,
['sign']
).then(function(derivedKey) {
console.log('derivedKey: '+derivedKey);
});
});
}
but at last result of console.log('derivedKey: '+derivedKey);
is this:
derivedKey: [object CryptoKey]
now how convert derivedKey to its corresponding seed as hex string ?
javascript cryptography
javascript cryptography
asked 2 days ago
saeid ezzati
162215
162215
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
finally I found that with crypto.subtle.exportKey
I can get result of CryptoKey
as ArrayBuffer
window.crypto.subtle.importKey(
'raw',
stringToArrayBuffer(mnemonic),
{
name: 'PBKDF2',
},
false,
['deriveKey']
).then((importedKey) => {
crypto.subtle.deriveKey({
name: "PBKDF2",
salt: stringToArrayBuffer('mnemonic'+passphrase),
iterations: 2048,
hash: { name: 'SHA-512' }
},
importedKey,
{
name: 'HMAC',
hash: 'SHA-512',
length: 512
},
true,
['sign']
).then(function(derivedKey) {
crypto.subtle.exportKey('raw',derivedKey).then((exportedKey) => {
console.log(convertArrayBufferToHexaDecimal(exportedKey));
});
});
})
function convertArrayBufferToHexaDecimal(buffer)
{
var data_view = new DataView(buffer)
var iii, len, hex = '', c;
for(iii = 0, len = data_view.byteLength; iii < len; iii += 1)
{
c = data_view.getUint8(iii).toString(16);
if(c.length < 2)
{
c = '0' + c;
}
hex += c;
}
return hex;
}
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
finally I found that with crypto.subtle.exportKey
I can get result of CryptoKey
as ArrayBuffer
window.crypto.subtle.importKey(
'raw',
stringToArrayBuffer(mnemonic),
{
name: 'PBKDF2',
},
false,
['deriveKey']
).then((importedKey) => {
crypto.subtle.deriveKey({
name: "PBKDF2",
salt: stringToArrayBuffer('mnemonic'+passphrase),
iterations: 2048,
hash: { name: 'SHA-512' }
},
importedKey,
{
name: 'HMAC',
hash: 'SHA-512',
length: 512
},
true,
['sign']
).then(function(derivedKey) {
crypto.subtle.exportKey('raw',derivedKey).then((exportedKey) => {
console.log(convertArrayBufferToHexaDecimal(exportedKey));
});
});
})
function convertArrayBufferToHexaDecimal(buffer)
{
var data_view = new DataView(buffer)
var iii, len, hex = '', c;
for(iii = 0, len = data_view.byteLength; iii < len; iii += 1)
{
c = data_view.getUint8(iii).toString(16);
if(c.length < 2)
{
c = '0' + c;
}
hex += c;
}
return hex;
}
add a comment |
up vote
0
down vote
finally I found that with crypto.subtle.exportKey
I can get result of CryptoKey
as ArrayBuffer
window.crypto.subtle.importKey(
'raw',
stringToArrayBuffer(mnemonic),
{
name: 'PBKDF2',
},
false,
['deriveKey']
).then((importedKey) => {
crypto.subtle.deriveKey({
name: "PBKDF2",
salt: stringToArrayBuffer('mnemonic'+passphrase),
iterations: 2048,
hash: { name: 'SHA-512' }
},
importedKey,
{
name: 'HMAC',
hash: 'SHA-512',
length: 512
},
true,
['sign']
).then(function(derivedKey) {
crypto.subtle.exportKey('raw',derivedKey).then((exportedKey) => {
console.log(convertArrayBufferToHexaDecimal(exportedKey));
});
});
})
function convertArrayBufferToHexaDecimal(buffer)
{
var data_view = new DataView(buffer)
var iii, len, hex = '', c;
for(iii = 0, len = data_view.byteLength; iii < len; iii += 1)
{
c = data_view.getUint8(iii).toString(16);
if(c.length < 2)
{
c = '0' + c;
}
hex += c;
}
return hex;
}
add a comment |
up vote
0
down vote
up vote
0
down vote
finally I found that with crypto.subtle.exportKey
I can get result of CryptoKey
as ArrayBuffer
window.crypto.subtle.importKey(
'raw',
stringToArrayBuffer(mnemonic),
{
name: 'PBKDF2',
},
false,
['deriveKey']
).then((importedKey) => {
crypto.subtle.deriveKey({
name: "PBKDF2",
salt: stringToArrayBuffer('mnemonic'+passphrase),
iterations: 2048,
hash: { name: 'SHA-512' }
},
importedKey,
{
name: 'HMAC',
hash: 'SHA-512',
length: 512
},
true,
['sign']
).then(function(derivedKey) {
crypto.subtle.exportKey('raw',derivedKey).then((exportedKey) => {
console.log(convertArrayBufferToHexaDecimal(exportedKey));
});
});
})
function convertArrayBufferToHexaDecimal(buffer)
{
var data_view = new DataView(buffer)
var iii, len, hex = '', c;
for(iii = 0, len = data_view.byteLength; iii < len; iii += 1)
{
c = data_view.getUint8(iii).toString(16);
if(c.length < 2)
{
c = '0' + c;
}
hex += c;
}
return hex;
}
finally I found that with crypto.subtle.exportKey
I can get result of CryptoKey
as ArrayBuffer
window.crypto.subtle.importKey(
'raw',
stringToArrayBuffer(mnemonic),
{
name: 'PBKDF2',
},
false,
['deriveKey']
).then((importedKey) => {
crypto.subtle.deriveKey({
name: "PBKDF2",
salt: stringToArrayBuffer('mnemonic'+passphrase),
iterations: 2048,
hash: { name: 'SHA-512' }
},
importedKey,
{
name: 'HMAC',
hash: 'SHA-512',
length: 512
},
true,
['sign']
).then(function(derivedKey) {
crypto.subtle.exportKey('raw',derivedKey).then((exportedKey) => {
console.log(convertArrayBufferToHexaDecimal(exportedKey));
});
});
})
function convertArrayBufferToHexaDecimal(buffer)
{
var data_view = new DataView(buffer)
var iii, len, hex = '', c;
for(iii = 0, len = data_view.byteLength; iii < len; iii += 1)
{
c = data_view.getUint8(iii).toString(16);
if(c.length < 2)
{
c = '0' + c;
}
hex += c;
}
return hex;
}
edited yesterday
answered yesterday
saeid ezzati
162215
162215
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238462%2fconvert-crypto-subtle-derivekey-result-to-hex-string%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password