Generate address of 'private key' from user input I want to take a private key as input from the user and convert it to a wallet address using C#.
I have seen this in a tutorial to generate a random key:
Key privateKey = new Key();
PubKey publicKey = privateKey.PubKey;
Console.WriteLine(publicKey.GetAddress(ScriptPubKeyType.Legacy, Network.Main));

How do I convert a private key string from the user to a wallet address for main net?
Assuming the private key string in this example is pk
Console.WriteLine(&quot;Enter private key:&quot;);
string pk = Console.ReadLine();
var bitcoinPrivateKey = new BitcoinSecret(pk, Network.Main);

var legacy_address = bitcoinPrivateKey.GetAddress(ScriptPubKeyType.Legacy);

Console.WriteLine(&quot;Legacy Address :&quot; + legacy_address);

And if you want to get p2sh-segwit and bech32 address, add below lines:
var p2shsegwit_address = bitcoinPrivateKey.GetAddress(ScriptPubKeyType.SegwitP2SH);
var nativesegwit_address = bitcoinPrivateKey.GetAddress(ScriptPubKeyType.Segwit);

Console.WriteLine(&quot;P2SH-Segwit Address :&quot; + p2shsegwit_address);
Console.WriteLine(&quot;Bech32 Address :&quot; + nativesegwit_address);