簡體   English   中英

從比特幣私鑰中搜索公鑰

[英]Retrive Public key from a Bitcoin Private Key

我如何從比特幣私鑰獲得比特幣地址。

我理解整個方法,除了第一個方法,公鑰及其x和y線來自哈希/私鑰。

如果我可以在php中獲得代碼示例,那對我來說會更有幫助。

初學者使用以下庫:

https://github.com/RobKohr/PHP-Bitcoin-Address-Creator

你可以選擇使用vanitygen的后端並通過exec()shell_exec()甚至更好的escapeshellarg()生成地址。 除了這兩種方法之外,您的選擇是使用bitcoind服務器設置rpc。

當然還有更復雜的解決方案,例如這里的內容(coinbit.tk,一個在javascript中生成私鑰的splitkey虛榮地址生成器)

https://github.com/RobKohr/PHP-Bitcoin-Address-Creator

如果仍有問題,請參閱以下主題。

https://bitcoin.stackexchange.com/questions/2289/php-script-to-create-private-key-public-address

https://bitcointalk.org/index.php?topic=81626.0

這是一個NodeJS腳本來自WIF - >私鑰 - >公鑰 - >二進制地址 - >人類可讀地址

// EXAMPLE: node wif_details.js 5JuHN27YsJktraQYGgLeihxZ2bwQbFANFdpc8gtDgqyyJsZJQB6

const ecc = require('eosjs-ecc');
const base58 = require('bs58');
const ripemd160 = require('ripemd160')

const wif = process.argv[2];
console.log("WIF: ", wif);

const privkey = ecc.PrivateKey.fromString(wif);
console.log("Private Key: ", privkey.toBuffer().toString('hex'));

const compressed_pubkey = privkey.toPublic();
const uncompressed_pubkey = compressed_pubkey.toUncompressed();
console.log("Public key (compressed): ", compressed_pubkey.toHex());
console.log("Public key: ", uncompressed_pubkey.toHex());

const hash1 = ecc.sha256(compressed_pubkey.toBuffer());
const hash2 = new ripemd160().update(Buffer.from(hash1, 'hex')).digest('hex');
const hash3 = ecc.sha256(uncompressed_pubkey.toBuffer());
const hash4 = new ripemd160().update(Buffer.from(hash3, 'hex')).digest('hex');
const with_prefix_compressed = '00' + hash2;
const with_prefix_uncompressed = '00' + hash4;

const hash5 = ecc.sha256(Buffer.from(with_prefix_compressed, 'hex'));
const hash6 = ecc.sha256(Buffer.from(hash5, 'hex'));
const hash7 = ecc.sha256(Buffer.from(with_prefix_uncompressed, 'hex'));
const hash8 = ecc.sha256(Buffer.from(hash7, 'hex'));
const binary_address_compressed = with_prefix_compressed + hash6.slice(0,8);
const binary_address_uncompressed = with_prefix_uncompressed + hash8.slice(0,8);
console.log("Binary address (compressed): ", binary_address_compressed);
console.log("Binary address: ", binary_address_uncompressed);

const bitcoin_address_compressed = base58.encode(Buffer.from(binary_address_compressed, 'hex'));
const bitcoin_address_uncompressed = base58.encode(Buffer.from(binary_address_uncompressed, 'hex'));
console.log("Bitcoin address (compressed): ", bitcoin_address_compressed);
console.log("Bitcoin address: ", bitcoin_address_uncompressed);

這不是你想要的,因為你從一個特定的私鑰開始。 但是,如果您只想生成私鑰和公鑰,您可能需要查看vanitygen,它會生成兩者。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM