Last active
June 7, 2024 04:30
-
-
Save jmkim/1f885d4ca0631d45444715435da18082 to your computer and use it in GitHub Desktop.
Automatic GPG key generation script with fancy output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Key-Type: 1 | |
Key-Length: 4096 | |
Subkey-Type: 1 | |
Subkey-Length: 4096 | |
Name-Real: John Doe | |
Name-Email: john.doe@example.com | |
Expire-Date: 0 | |
%no-protection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Key creation | |
GPG_REVOKE_LOCATE="$(gpg --batch --gen-key gen-key-script 2>&1)" | |
# Cut GPG keyID from the key creation output (revoke location msg) | |
GPG_KEYID="$(echo "$GPG_REVOKE_LOCATE" | cut -d '/' -f 6 | cut -d '.' -f 1)" | |
# ID Substrings from each 4 characters | |
GPG_KEYID4_1="${GPG_KEYID:0:4}" | |
GPG_KEYID4_2="${GPG_KEYID:4:4}" | |
GPG_KEYID4_3="${GPG_KEYID:8:4}" | |
GPG_KEYID4_4="${GPG_KEYID:12:4}" | |
GPG_KEYID4_5="${GPG_KEYID:16:4}" | |
GPG_KEYID4_6="${GPG_KEYID:20:4}" | |
GPG_KEYID4_7="${GPG_KEYID:24:4}" | |
GPG_KEYID4_8="${GPG_KEYID:28:4}" | |
GPG_KEYID4_9="${GPG_KEYID:32:4}" | |
GPG_KEYID4_10="${GPG_KEYID:36:4}" | |
# ID strings | |
GPG_KEYID_LAST8=" $GPG_KEYID4_9 $GPG_KEYID4_10" | |
GPG_KEYID_LAST16=" $GPG_KEYID4_7 $GPG_KEYID4_8 $GPG_KEYID4_9 $GPG_KEYID4_10" | |
GPG_KEYID_ALL="$GPG_KEYID4_1 $GPG_KEYID4_2 $GPG_KEYID4_3 $GPG_KEYID4_4 $GPG_KEYID4_5 $GPG_KEYID4_6 $GPG_KEYID4_7 $GPG_KEYID4_8 $GPG_KEYID4_9 $GPG_KEYID4_10" | |
# Show ID strings | |
echo "$GPG_KEYID_LAST8" | |
echo "$GPG_KEYID_LAST16" | |
echo "$GPG_KEYID_ALL" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
E974 1914 | |
4D4F 78F3 E974 1914 | |
6C9A 2674 50A0 6B26 384C 4924 4D4F 78F3 E974 1914 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Infinite loop example in bash:
Output looks like: