Let’s Take a Closer Look at Cryptography Keys in Bitcoin

, ,
Cryptography Keys

Before we start on cryptographic keys, let’s take a minute to recap the discussion in the last post about the relationship between cryptography and Bitcoin.

Cryptography is at the very core of Bitcoin. It includes both the keys that to crypto wallets hold and the ability to link transactions (or blocks) in the blockchain. We talked about asymmetric (or public-key) cryptography which uses both a private key and a public key to encrypt and decrypt messages, and we briefly looked at hashing functions which takes messages of any size and garbles them into a fixed bit-length hash.

For this post, let’s dive deeper into the keys used by Bitcoin. This material can get very technical quickly, so we can look at some parts in depth while only briefly addressing others. I’ll provide links at the end so you can do more research if you so desire. We’ll save the hashing functions for a later post so that we can really spend some time understanding what’s going on – stay tuned!

Bitcoin Keys

Let’s start with Bitcoin key generation (you may also hear a key referred to as an “address”; I’ll explain why). A private key is a 256-bit representation of random data from a function on a computer. These functions can be pseudo-random number generators (PRNGs) or a random source from nature. (atmospheric noise, lava lamps, and even lasers are used to get random data!).

The public key is a 512-bit representation of random data. To get an official Bitcoin address, the public key is input into several functions to get a specific representation of the key as a base58 number. (there are a variety of algorithms that can be used, so the length may vary slightly). For those of you without 58 fingers and toes, this means that an address can be represented by most uppercase and lowercase letters in the English alphabet and the numbers 1 – 9.

Private and Public Keys

The underlying key pair (private and public) is inextricably linked using the Elliptic Curve Digital Signature Algorithm (ECDSA). This means that even though the public key changes its appearance slightly, the two keys are still bound together mathematically. You might be thinking, “If these are linked, how do I know that an attacker couldn’t just reverse engineer the public key and steal my wallet’s funds using my private key?”

Luckily, thanks to way public-key cryptography works, this is “practically” impossible. I say this because anything in the world of computational cryptography can eventually be broken. Although, to break something like a Bitcoin key would take many billions of years using the fastest supercomputers in the world.

Private Key Importance

Alright, now that we’ve laid a foundation of the theory behind keys, let’s discuss how use in the real world. First, a public service announcement: your private keys need to be kept 100% private. If anyone ever discovers your private keys, they will be immediately able to send your Bitcoins to a wallet of their choosing. This can quickly deplete your entire wallet.

Why? A private key is used to tell the world that you are authorizing a payment of x Bitcoins to another party with address abc123. You are able to essentially sign off on this transaction, and because your private key is linked to your public key, anyone can check the ledger where your public key is found and guarantee that you were the one who OK’d this transfer.

Like we just mentioned, private keys are used to sign transactions. This verifies that you have initiated a release of coins from your wallet and are sending them to someone else’s wallet. A transaction has quite a bit of information in it, but for now let’s just stick to what’s relevant to a private key.

Remember the hash we talked about last time? We’ll dive a bit deeper into hashes later. For now, it’s good enough to know that the transaction itself is hashed and signed with your private key. Because the private key / public key link is permanent, anyone within the Bitcoin community can use your public key to decode the transaction, read all of its details, and confirm that a transfer has taken place.

Public Key Purpose

We’ve talked about the private key in detail; what about the public key?

Remember, in the world of Bitcoin, the public key is usually a base58 expression consisting of 26-35 characters. (for you nerds out there: it’s a 25-byte binary address that is base58 encoded to a variable string length) This is the address to which someone sends a payment, almost like a street address for receiving mail. You aren’t stuck with one or even two public addresses. However, you can use as many addresses as you like as long as you keep up with the private keys on the backend. This means that, if you are privacy conscious, you can create a new public key each time you want to receive a payment for a good or service to keep the linking of multiple payments to a minimum. This could get a little dicey when attempting to spend your coins. We can save that discussion for another article.

Can Two People Have the Same Bitcoin Address?

How can you be sure that you don’t accidentally end up with the same address as another user? This would be a big hassle because someone could attempt to pay you 10,000 Bitcoins for 2 pizzas, but the money might accidentally end up in someone else’s wallet. Let’s look at the basic facts of the matter. A 256-bit private key means that your key is 1 out of 2^256 possible values.

To put this numerically, you have a 1 in 1.157×10^77 chance of having the same private address as someone else. And remember that public addresses are 512 bits long. If your head is spinning at the size of these numbers, you’re not alone. The possibility of this happening is so incredibly small that we can say it is practically impossible.

Cryptography Key Resources

Like I said at the top, there is so much more you could dive into if you so desire. Check out the links below if you want to get more in-depth information into the keys in Bitcoin:

Well, hopefully you understand what private and public keys are and how they Bitcoin uses them. In the next article, we’re going to explore more about hashing. What it is, why it’s useful, and how Bitcoin uses it. See you then!