bitshares网页钱包备份解密尝试
const bitsharesjs = require('bitsharesjs'); | |
const PrivateKey = bitsharesjs.PrivateKey; | |
const PublicKey = bitsharesjs.PublicKey; | |
const Aes = bitsharesjs.Aes; | |
const decompress = require('lzma').decompress; | |
if( process.argv.length != 4 ){ | |
console.error("usage: " + process.argv[1] + " <binfile> <password>"); | |
process.exit(1); | |
} | |
const binfilePath = process.argv[2]; | |
const password = process.argv[3]; | |
const fs = require('fs'); | |
// copied from bitshares-ui/web/app/actions/WalletActions.js | |
function decryptWalletBackup(backup_wif, backup_buffer) { | |
return new Promise( (resolve, reject) => { | |
if( ! Buffer.isBuffer(backup_buffer)) | |
backup_buffer = new Buffer(backup_buffer, "binary"); | |
let private_key = PrivateKey.fromWif(backup_wif); | |
let public_key; | |
try { | |
public_key = PublicKey.fromBuffer(backup_buffer.slice(0, 33)); | |
} catch(e) { | |
console.error(e, e.stack); | |
throw new Error("Invalid backup file"); | |
} | |
backup_buffer = backup_buffer.slice(33); | |
try { | |
backup_buffer = Aes.decrypt_with_checksum( | |
private_key, public_key, null/*nonce*/, backup_buffer); | |
} catch(error) { | |
console.error("Error decrypting wallet", error, error.stack); | |
reject("invalid_decryption_key"); | |
return; | |
} | |
try { | |
decompress(backup_buffer, wallet_string => { | |
try { | |
let wallet_object = JSON.parse(wallet_string); | |
resolve(wallet_object); | |
} catch(error) { | |
if( ! wallet_string) wallet_string = ""; | |
console.error("Error parsing wallet json", | |
wallet_string.substring(0,10)+ "..."); | |
reject("Error parsing wallet json"); | |
} | |
}); | |
} catch(error) { | |
console.error("Error decompressing wallet", error, error.stack); | |
reject("Error decompressing wallet"); | |
return; | |
} | |
}); | |
} | |
fs.readFile(binfilePath, function(err, buf){ | |
if( err ){ | |
console.error(`read file error, please ensure the file path | |
is correct and you have access right.`); | |
process.exit(1); | |
} | |
const privateKey = PrivateKey.fromSeed(password || ''); | |
console.log(privateKey.toWif()); | |
decryptWalletBackup(privateKey.toWif(), buf) | |
.then( console.log) | |
.catch( console.error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
pluswave commentedMay 2, 2017
依赖两个库,bitsharesjs和lzma