寻找丢失的以太坊私钥

问题描述 投票:0回答:1

我正在测试一个脚本,当我丢失了部分 64 个字符时,它可以恢复以太坊私钥的一部分。我正在使用的代码似乎按预期工作,这是我在 Google 上找到的。但是,当我按原样运行代码时,我收到消息 “由于安全和可用性问题,Buffer() 已被弃用。请改用 Buffer.alloc()、Buffer.allocUnsafe() 或 Buffer.from() 方法。”

修改这部分使用alloc或from后,代码看起来运行正常,但没有显示实际匹配的私钥。

const util = require('ethereumjs-util');
const Wallet = require('ethereumjs-wallet');


var possible = 'abcdef1234567890';
var basePrivateKey = '383d6c71f33d16d8775f3845d0b40ec141205e8e4124520f70fe24d4547a';
//
var charsMissing = 64 - basePrivateKey.length;
var targetPublicAddress = ' 0x019846f2E867E13e234900EE594702461253A06F';
var missingPart = '';
for (var i = 0; i < charsMissing; i++) {
  missingPart = missingPart.concat('f');
}
var maxVal = parseInt(missingPart, 16);

console.log(
  ' \n ' +
    'searching for address : ' +
    targetPublicAddress +
    ' \n ' +
    'base private key      : ' +
    basePrivateKey +
    ' \n ' +
    'missing chars         : ' +
    charsMissing +
    ' \n ' +
    "it will be quiet now. if you don't see anything below me, it's working on finding your key." +
    ' \n ' +
    "If you see something below that doesn't say 'FOUND KEY!', you have an error" +
    ' \n '
);

function makeHexString(numb) {
  var hex = numb.toString(16);
  for (var i = 0; i < charsMissing - hex.length; i++) hex = '0' + hex;
  return hex;
}


for (var i = 0; i <= maxVal; i++) {
  try {
    var endPrivateKey = makeHexString(i);
    var privateKeyGuess = basePrivateKey + endPrivateKey;
    var wallet = Wallet.fromPrivateKey(new Buffer(privateKeyGuess, 'hex'));
    var publicAddress = util.bufferToHex(wallet.getAddress());
    // console.log(i + ": " + endPrivateKey)
    if (publicAddress.toLowerCase() == targetPublicAddress.toLowerCase()) {
      console.log(
        '\n \n \n \n ********************************** FOUND PRIVATE KEY: ' +
          privateKeyGuess +
          ' \n matching address ' +
          targetPublicAddress +
          ' \n \n \n \n '
      );
      process.exit();
    }
  } catch (e) {
    null;
  }

  if (i % 100000 === 0) {
    console.log('checked', i, 'keys');
  }
}

出于测试目的,我插入了不包括私钥“383d6c71f33d16d8775f3845d0b40ec141205e8e4124520f70fe24d4547a544c”中最后4个字符的代码。运行代码时,私钥和地址的匹配过程似乎运行正常。但是,即使该过程完成后,也不会显示匹配的密钥。我该如何解决这个问题?

ethereum brute-force wallet
1个回答
0
投票

有几个问题可以让我更轻松地提供帮助。

  1. 在您的真实场景(不是您的测试)中,缺少多少个字符?
  2. 你知道这些缺失在哪里吗? (周六/结束/未知)

期待您的回复

© www.soinside.com 2019 - 2024. All rights reserved.