Bitcoin Forum
September 24, 2024, 04:35:48 AM *
News: Latest Bitcoin Core release: 27.1 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: NBitcoin: public key to address?  (Read 151 times)
BlackHatCoiner (OP)
Legendary
*
Offline Offline

Activity: 1652
Merit: 8146


Bitcoin is a royal fork


View Profile WWW
December 06, 2020, 11:59:41 AM
 #1

I have a hex string (66 chars long) and I want to convert it to a legacy address. I'm searching for a simple way that is already implemented on NBitcoin, so I won't have to spend time writing this on C#. The problem I face is that I can only convert a private key hex to address and not a public key hex. Is there any simple way to do it?

string hex -> PubKey -> Address

A-Bolt
Legendary
*
Offline Offline

Activity: 2326
Merit: 2365


View Profile
December 06, 2020, 03:38:52 PM
Merited by ABCbits (1), BlackHatCoiner (1)
 #2

string hex -> PubKey -> Address

Code:
String strPubKey = "03d322a42421f709d1b6253ecd0c442059534644544276ac3f964154e4b1ca56f4";
var pubKey = new PubKey(strPubKey);
var addr = pubKey.GetAddress(ScriptPubKeyType.Legacy, Network.Main);
Console.WriteLine(addr.ToString());
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!