Unit 2: Cryptographic Algorithms
Often when someone hears the word "cryptography", they think only of encrypting or hiding data. However, the branch of math that is cryptography includes a wide variety of functions that serve many purposes besides just hiding or encrypting data. In fact, Bitcoin doesn't encrypt any of its blockchain data. What Bitcoin does do is hash and sign data.
In this unit, we'll cover the basics of cryptography, including hashing and signing data, and explain the field's evolution from symmetric to asymmetric encryption. We'll then dig into public and private keys and how Bitcoin uses them in addresses and transactions.
Completing this unit should take you approximately 2 hours.
Upon successful completion of this unit, you will be able to:
- differentiate between the cryptographic functions that are used in Bitcoin;
- differentiate between symmetric and asymmetric encryption;
- explain the difference between public and private keys;
- explain the significance of private keys in asymmetric cryptography and in Bitcoin;
- summarize the relationship between keys and Bitcoin addresses; and
- use a public and private key pair to encrypt and decrypt data.
2.1: What is Cryptography?
Bitcoin is called a cryptocurrency because of its heavy use of cryptography. Here we'll take a quick look at symmetric and asymmetric encryption, as well as the two cryptographic functions that Bitcoin uses: digital signatures and hashing.
2.2: Cryptographic Keys
Now that we've covered the basics of public and private keys, let's dive in a bit deeper and take a look at how Bitcoin generates these keys.
2.3: The Basics of Hashing
Hashing is used extensively in Bitcoin, from data structures to mining, transaction IDs, and more. Hashing algorithms have many properties that make them very useful. But not all hashing algorithms are the same. SHA256, the algorithm that Bitcoin uses, is well suited to Bitcoin's needs.
This brief video will introduce you to the basics of hashing.
2.4: Keys and Transaction Signatures
A Bitcoin transaction isn't valid without a signature. Signatures are a big component in preventing fraud on the network. And where do these signatures come from? Yup, private keys! Your private keys give you the ability to transfer your Bitcoin. This short video will introduce you to the basics of cryptographic signatures.
2.5: Keys and Bitcoin Addresses
One of the ways that Bitcoin uses cryptographic keys is in generating Bitcoin addresses, which are often derived from public keys. This chapter covers public keys and how they are used to generate addresses.
The security and integrity of Bitcoin depend largely on private keys, and these keys are randomly generated large numbers. This often feels a bit insecure. You may worry that someone may coincidentally generate the same private key as you. It can be a bit difficult to comprehend the magnitude of the numbers being dealt with here. Since this is such an important piece of the Bitcoin system, let's take a few minutes to appreciate the incredible unlikelihood of generating the same private key as someone else on the network.
2.6: Exercise: Encrypt and Decrypt Data
While Bitcoin doesn't actually encrypt any data, it relies upon public and private keys pairs. Working with Bitcoin requires familiarity with these keys and the best way to get familiar with technology is to use it! In this exercise, we'll generate a key pair and use those keys to encrypt and decrypt data with a bit of Python.