Skip to content

Commit

Permalink
fix: off-by-one
Browse files Browse the repository at this point in the history
  • Loading branch information
encody committed May 17, 2024
1 parent 8995171 commit 3bae11c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion content/blog/what-does-my-rsa-public-key-actually-mean.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ f0 10 75 73 65 72 40 65 78 61 6d 70 6c 65 2e 63 |..user@example.c|
6f 6d f1 0b 6d 79 5f 75 73 65 72 6e 61 6d 65 |om..my_username|
```

The idea is that the first byte (or bytes, depending on the format) represent a **tag**. In the basic example above, the byte `f0` means email, and the byte `f1` means username. The next byte(s) indicates the **length** of the information. So, `f0 10` means that we're expecting a 16 byte long email next. So, we read the next 16 bytes `75 73 65 72 40 65 78 61 6d 70 6c 65 2e 63 6f 6d` and that should be an email **value**. If we decode those bytes as ASCII, what do we get? `user@example.com`. _Voilà!_ Now rinse and repeat for the next bytes: a `f1` username… that is `0b 10` bytes long… `6d 79 5f 75 73 65 72 6e 61 6d 65`—`my_username`!
The idea is that the first byte (or bytes, depending on the format) represent a **tag**. In the basic example above, the byte `f0` means email, and the byte `f1` means username. The next byte(s) indicates the **length** of the information. So, `f0 10` means that we're expecting a 16 byte-long email next. So, we read the next 16 bytes `75 73 65 72 40 65 78 61 6d 70 6c 65 2e 63 6f 6d` and that should be an email **value**. If we decode those bytes as ASCII, what do we get? `user@example.com`. _Voilà!_ Now rinse and repeat for the next bytes: a `f1` username… that is `0b` 11 bytes long… `6d 79 5f 75 73 65 72 6e 61 6d 65`—`my_username`!

ASN.1 (Abstract Syntax Notation One) is a notation for describing data structures. It can represent integers, strings, sequences, booleans, etc. [There are lots of different ASN.1 encoding rules](https://en.wikipedia.org/wiki/Abstract_Syntax_Notation_One#Encodings), but we're interested in the ones for binary, specifically, the [Distinguished Encoding Rules (DER)](https://docs.microsoft.com/en-us/windows/win32/seccertenroll/about-der-encoding-of-asn-1-types).

Expand Down

0 comments on commit 3bae11c

Please sign in to comment.