Adds note about generating random strings.
This commit is contained in:
1 parent
8f561a9586
commit
dc300fb01c
1 file changed
+14
@@ -19,3 +19,17 @@ nix run 'nixpkgs#imagemagick' -- input.jpg -resize 1200x800 -strip -quality 85 o
|
|||||||
```
|
```
|
||||||
|
|
||||||
There are lots of options that can be passed to the [image geometry](https://imagemagick.org/command-line-processing/#geometry). The default for pixel sizes is to treat it as a maximum and preserve the aspect ratio. If only a width is given then height is automatically determined from the aspect ratio.
|
There are lots of options that can be passed to the [image geometry](https://imagemagick.org/command-line-processing/#geometry). The default for pixel sizes is to treat it as a maximum and preserve the aspect ratio. If only a width is given then height is automatically determined from the aspect ratio.
|
||||||
|
|
||||||
|
## Generate a random string
|
||||||
|
|
||||||
|
Many times I want a random string to act as a secret shared between two services. This comes up all the time when configuring services on my home server. The common `openssl` library will generate secure random strings for you.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
openssl rand -base64 32
|
||||||
|
```
|
||||||
|
|
||||||
|
- `rand` instructs it to generate a random number or byte sequence
|
||||||
|
- `-base64` instructs it to output [Base64](https://en.wikipedia.org/wiki/Base64) encoded data. You can also use `-hex` if you just want Base 16, but that's more verbose.
|
||||||
|
- `32` is the number of bytes of data to produce.
|
||||||
|
|
||||||
|
Base64 has only 6 bytes per character, while the system generates multiples of 8. This creates a mismatch since it's generating `32 * 8 = 256` bits of data which is not a multiple of 6. This leaves 2 bits extra. Base64 encodes blocks of 3 bytes at a time into 4 output characters.In this case we need 8 extra bits to get to a multiple of three (257). These get encoded as zeros to fill out the character and a trailing `=` is appended to indicate a non-coding character.
|
||||||
Reference in new issue
Block a user