Private key
Private keys are often represented in Base58Check called a Bitcoin Secret (also known as Wallet Import Format or simply WIF), like Bitcoin Addresses.
1
Key privateKey = new Key(); // generate a random private key
2
BitcoinSecret mainNetPrivateKey = privateKey.GetBitcoinSecret(Network.Main); // generate our Bitcoin secret(also known as Wallet Import Format or simply WIF) from our private key for the mainnet
3
BitcoinSecret testNetPrivateKey = privateKey.GetBitcoinSecret(Network.TestNet); // generate our Bitcoin secret(also known as Wallet Import Format or simply WIF) from our private key for the testnet
4
Console.WriteLine(mainNetPrivateKey); // L5B67zvrndS5c71EjkrTJZ99UaoVbMUAK58GKdQUfYCpAa6jypvn
5
Console.WriteLine(testNetPrivateKey); // cVY5auviDh8LmYUW8AfafseD6p6uFoZrP7GjS3rzAerpRKE9Wmuz
6
7
bool WifIsBitcoinSecret = mainNetPrivateKey == privateKey.GetWif(Network.Main);
8
Console.WriteLine(WifIsBitcoinSecret); // True
Copied!
Note that it is easy to go from BitcoinSecret to private Key. On the other hand, it is impossible to go from a Bitcoin Address to Public Key because the Bitcoin Address contains a hash of the Public Key, not the Public Key itself. Process this information by examining the similarities between these two codeblocks:
1
Key privateKey = new Key(); // generate a random private key
2
BitcoinSecret bitcoinSecret = privateKey.GetWif(Network.Main); // L5B67zvrndS5c71EjkrTJZ99UaoVbMUAK58GKdQUfYCpAa6jypvn
3
Key samePrivateKey = bitcoinSecret.PrivateKey;
4
Console.WriteLine(samePrivateKey == privateKey); // True
Copied!
1
PubKey publicKey = privateKey.PubKey;
2
BitcoinAddress bitcoinAddress = publicKey.GetAddress(ScriptPubKeyType.Legacy, Network.Main); // 1PUYsjwfNmX64wS368ZR5FMouTtUmvtmTY
3
//PubKey samePublicKey = bitcoinAddress.ItIsNotPossible;
Copied!

Exercise:

    1.
    Generate a private key on the mainnet and note it.
    2.
    Get the corresponding address.
    3.
    Send bitcoins to it. More than what you can afford to lose, so it will keep you focused and motivated to get them back during the following lessons.
Last modified 6mo ago
Copy link
Contents
Exercise: