no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
| — | pgp [2025/11/23 17:30] (current) – created TheFrugalGamer | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== PGP Encryption ====== | ||
| + | PGP is a type of encryption that is used for keeping messages secure all over the internet. The mathematics behind how it works are fairly complicated, | ||
| + | [[https:// | ||
| + | |||
| + | ===== Let's start by understanding symmetric encryption ===== | ||
| + | |||
| + | Most encryption is // | ||
| + | |||
| + | Symmetric encryption is pretty easy to understand: you probably played about with it when you were a young child! If you have a substitution cipher (swapping letters for symbols) that you shared with a friend, or if you agreed to " | ||
| + | |||
| + | The big problem with symmetric encryption is that we have to agree on the key, without it being intercepted. Like: Alice and Bob probably want to get together in the same room to agree what their ZIP file password will be, right? If Alice //phones// Bob to tell him the password, there' | ||
| + | |||
| + | ===== The solution? asymmetric encryption ===== | ||
| + | |||
| + | The solution to this is // | ||
| + | |||
| + | Asymmetric encryption exploits one of several mathematical phenomena that mean that //some mathematical operations are easy to prove, but hard to do//. For example, prime factorisation: | ||
| + | |||
| + | Prime factorisation is a classic example, but much asymmetric encryption nowadays uses elliptic curves instead (not least because prime factorisation might turn out to be something that quantum computers will be amazingly good at, thereby breaking the encryption much faster, assuming anybody ever manages to build a big one). Imagine you have a formula which draws an ellipse on a piece of graph paper. I choose a secret point on the ellipse and perform an operation that draws a line from it at a particular angle, so that my line hits another point on the ellipse. Then I do it again, and again, and again, hundreds of times. When I tell you the point that I ended up, it's insanely difficult for you to work out where I started, because you have to try many different points on the ellipse to work out where I was //last// move, and then work it back again and again. But if I //tell// you where I started, it's very easy for you to check that, yes, running the operation 100 times would have got me to where I finished. Hard to do, easy to prove. | ||
| + | |||
| + | If you didn't understand all of that, that's fine. Just trust me when I say that there are mathematical operations that are //easy to do one way, but hard to work backwards from.// And those are the basis of split-key encryption. | ||
| + | |||
| + | ===== So what about PGP ===== | ||
| + | |||
| + | All split-key encryption works basically the same way, but you asked about PGP: | ||
| + | |||
| + | Anybody can make a " | ||
| + | |||
| + | One of these two keys is called the " | ||
| + | |||
| + | The magic with split-key encryption is this: a message encrypted with one half of a keypair can only be decrypted with the other. And that means you can do two very, very clever things with it: | ||
| + | |||
| + | - **Encryption (sending messages so they can't be intercepted): | ||
| + | |||
| + | - **Signing (making sure a message was sent by its author).** Suppose I send you a message. I could send you my message, and I can send you a second copy of the message, but encrypted with my private key. You could decrypt the encrypted copy of the message using my public key (indeed: anybody can, because my public key is public!), compare it to the unencrypted version, and if they match: you know two things for sure: (1) that the message really came from me (because nobody else could have created a message that can be decrypted using my public key than the person controlling my private key, i.e. me), and (2) that it hasn't been tampered with in-transit (or else the decrypted copy wouldn' | ||
| + | |||
| + | Incidentally: | ||
| + | |||
| + | (PGP users can also " | ||
| + | |||
| + | ===== Okay, my head is spinning: just tell me how to do this! ===== | ||
| + | |||
| + | Want to try PGP. Cool! | ||
| + | |||
| + | The most popular implementation of PGP is, confusingly (but for hilarious and amazing reasons) called GPG. You can install command-line tools or graphical tools for a variety of operating systems). | ||
| + | |||
| + | I'm using a Linux command line right now, so I'm going to create a keypair. I type: | ||
| + | gpg --gen-key | ||
| + | |||
| + | It asks for some metadata (name, email etc., all of which is optional) and for a password to protect the key, and then soon it exists. If I run: | ||
| + | gpg --list-secret-keys | ||
| + | |||
| + | I can see my keyring; here's what mine looks like right now: | ||
| + | gpg --list-secret-keys | ||
| + | |||
| + | sec | ||
| + | B52B7F1159ECF9FD20482D32D9CC360817CAC036 | ||
| + | uid | ||
| + | ssb | ||
| + | |||
| + | I can get a copy of my public key, to share with the world, like this (note the " | ||
| + | gpg --armor --export B52B7F1159ECF9FD20482D32D9CC360817CAC036 | ||
| + | |||
| + | -----BEGIN PGP PUBLIC KEY BLOCK----- | ||
| + | |||
| + | mQGNBGkfWbwBDADZD0+efWXyREGSM8yDbXGx0ObZTNsZdPBsewiI891kYVkZE4Vt | ||
| + | jqzBa4eZ7QNL9lH/ | ||
| + | 68PRkyI20NFBm0PdmkIbdoKxWeUn3r5azhCtqhJY9dDGcpr1+XbxM74TGbT0MKXU | ||
| + | 3oEZrGzW4A/ | ||
| + | uADXJixz8XtsaGy9es2iaxovM+ej+BUqwWYWXzAPspCqhq1Uq0VrnV8jre9VwROk | ||
| + | ej1Itgt3Y5KT8CCFsVC0GO0GsCJp07XRX8Bje+PfYtlydE5HXJmEOk5FasDwI9Tp | ||
| + | 2sQWscSQMIXIOIsp89K3c+5Xe2i3TwMdsVsMSzAvrUJOTw0CvEp11KFokUfCpfjb | ||
| + | jxsLrXmzvBr8H23IxhQN7HEPUGL4Ky3xwN2qifw2BDy1Kg1jkisBBFayouRfQwy/ | ||
| + | oVuimn3HxegCEQsAEQEAAbQOVGV0c3kgTWNUZXN0ZXKJAdQEEwEKAD4WIQS1K38R | ||
| + | Wez5/ | ||
| + | AQIeAQIXgAAKCRDZzDYIF8rANsjoC/ | ||
| + | Jx8sxXrwUpptCePXv1aJn7rlwfpsrW3Q3hPkKnXNVCmHYqVsD5aWaIIt25ygpf+G | ||
| + | nFOKCmU4yGRCCVtCmc0GTVSXD1Ut0xdABkb0rGc8pYmvMN10UDPJL7ua8Z2KK/ | ||
| + | LtFslrav7ZLsa2qunLUhXdgoUb4fAs4BulMYdksUCvdAHbTD09+sxTVfJy5M50wp | ||
| + | pohUSsmJL9YywFMoy8MueJ0iL4bksVIpOhp15Ye5nK+ME4asVZ2FPq1dKHgr9f47 | ||
| + | eC8OBcKQmSPWbnKxZkOKQwCW9NGPRaZkMEEinonEtsnCCgAvL1vE0yuskFkWjTLH | ||
| + | MtL0dLNTEnf5f940YEq07mxnFEVeNHTKvs/ | ||
| + | pGDnKUW5VXUiPjmDwJsHzEHenyCPceCbEwREHcibGvU44HLcs/ | ||
| + | ZkCn2ezo8hkhJ+zxqMYv1Ee42h1sfZa5AY0EaR9ZvAEMAMZdsk1jlZY9MeCJzdfu | ||
| + | Jno5AwAsVh6DHptlZLjnnw6fWiqimu0k37MZUCAEgGTla7KaitIz4H/ | ||
| + | BllFk9FTmHmP4hTwQWs8+8i8sdazRctO+OmV7jQ+Rzvo5Wnza7+ZjlXeqqjRaHhz | ||
| + | 74Z9tvE3yFGvgABLbYsOn0gvuBU7hwMv5eY9X2G6/ | ||
| + | ddSvrHWfZsV+iRfElG02oYpuFMHADboDHUeqlrwSqcrE9UJWHSjYaqDPpxYJYZv4 | ||
| + | L7570ewXF9NTSarL82Uz74p1Qvb02oy8YT9XIpjpcXM2ivesPADS6iFML8JXBVKO | ||
| + | x7LNM/ | ||
| + | WHWczZYIaWjwqxlxMQvD4B75XKYq/ | ||
| + | dWgG8c9m++1IhKry1RWAKxiMG0wK/ | ||
| + | FiEEtSt/ | ||
| + | wDa0fwv+PmDUvCl1g+duLs0HBXSLL/ | ||
| + | +EKjkA5fc4f/ | ||
| + | bJwVsGpzN5MHk3qrmwbzizIz7QlgX4gMdoG1SiIWoLkxWNhx6fO/ | ||
| + | pQm0KA9PwwWOapuBpXy5+adkkgZ09tJf/ | ||
| + | 7MgdNuN9SGuG+t4wD2rNB0LbXTlOxM+HmwmTktaLljJisKoDfgOjbpWmevco2huJ | ||
| + | SXeA/ | ||
| + | tHYoL12ZhlIEyhHqky17N9+ePGnXMIKXT0Du9C8Z97avQy1iJPEPbIzi99Moj2sj | ||
| + | knBg6I7/ | ||
| + | Wtom7Lcm | ||
| + | =8NCK | ||
| + | -----END PGP PUBLIC KEY BLOCK----- | ||
| + | |||
| + | |||
| + | B52B7F1159ECF9FD20482D32D9CC360817CAC036, | ||
| + | |||
| + | Anybody can import that into their own keyring with "gpg --import" | ||
| + | gpg --armor --encrypt | ||
| + | |||
| + | You did not specify a user ID. (you may use " | ||
| + | |||
| + | Current recipients: | ||
| + | |||
| + | Enter the user ID. End with an empty line: B52B7F1159ECF9FD20482D32D9CC360817CAC036 | ||
| + | |||
| + | Current recipients: | ||
| + | rsa3072/ | ||
| + | |||
| + | Enter the user ID. End with an empty line: | ||
| + | |||
| + | This is my secret message! | ||
| + | When I'm done typing it I'll press CTRL+D! | ||
| + | |||
| + | -----BEGIN PGP MESSAGE----- | ||
| + | |||
| + | hQGMA9+26gjR5U8cAQwAmHkUhdvE5GbbzbS4F3gPq61fU8F9xb8eTQ4LocYo9tn4 | ||
| + | r/ | ||
| + | Cnu9xFiKk2NXWAQ9B/ | ||
| + | u7KhdO4S+Nyhe5q7eYYnWNGCrhOGxmRt7DwdlRZkBCAyUx0BI2TN5jZSD3pEycGw | ||
| + | TQ56TijZuP2510ybJ8X8wosj1Jhb+AnGm7SQwLX4xDHKrlVtI7U71SpS1daEtCz+ | ||
| + | uj23SXZkB0tjoXpLd4s8lqiTSgTQsJD1z+12+FsR6O/ | ||
| + | Kvk+t7UBVdRii5zuBxp9HD2hihQPO6fx5ya/ | ||
| + | Z7kht0EUeiDfOE0xSEEW8ON2pyOwWWxdKUg4goiXSqUwy+h/ | ||
| + | gPm0LNrUEZHYoBbmEvvU0n8BdFuMN8NZeWzYM53Omjdefgn4jPiCH6o/ | ||
| + | hk4xpeFBOF2KJK3ak2KBBpwXMBQaL3h1xo5uHIXgS09fgarRl/ | ||
| + | A123sHeI+pqazjndF9uDWlQT7LRQ3iuxmFMlcWj6d5AlQ7e+/ | ||
| + | =0jDF | ||
| + | -----END PGP MESSAGE----- | ||
| + | |||
| + | There we have it! A secret message that can only be decoded using Testy McTester' | ||
| + | |||
| + | To try it, I put it into a file called " | ||
| + | gpg --decrypt encrypted.txt # (it prompted me for my private key's password at this point!) | ||
| + | |||
| + | gpg: encrypted with 3072-bit RSA key, ID DFB6EA08D1E54F1C, | ||
| + | "Tetsy McTester" | ||
| + | |||
| + | This is my secret message! | ||
| + | When I'm done typing it I'll press CTRL+D! | ||
| + | |||
| + | If I delete my new secret key: | ||
| + | gpg --delete-secret-keys B52B7F1159ECF9FD20482D32D9CC360817CAC036 | ||
| + | |||
| + | gpg (GnuPG) 2.2.27; Copyright (C) 2021 Free Software Foundation, Inc. | ||
| + | This is free software: you are free to change and redistribute it. | ||
| + | There is NO WARRANTY, to the extent permitted by law. | ||
| + | |||
| + | |||
| + | sec rsa3072/ | ||
| + | |||
| + | Delete this key from the keyring? (y/N) y | ||
| + | This is a secret key! - really delete? (y/N) y | ||
| + | |||
| + | Then there' | ||
| + | gpg --decrypt encrypted.txt | ||
| + | |||
| + | gpg: encrypted with 3072-bit RSA key, ID DFB6EA08D1E54F1C, | ||
| + | "Tetsy McTester" | ||
| + | gpg: decryption failed: No secret key | ||
| + | |||
| + | |||
| + | That was a whirlwind tour of PGP/GPG, done in just about the hardest possible way. Most people using PGP for email use a plugin for their email software to do it for them, which does most of the heavy lifting. You can even use an email provider like ProtonMail who do it for you in your browser, which is pretty cool. | ||
