Created
November 30, 2017 14:45
-
-
Save willinspire/58cf020d256685f3afea35b7e49c56c1 to your computer and use it in GitHub Desktop.
Encrypt a string within a shell script
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
################ | |
# # | |
# # | |
# ENCRYPTING # | |
# SHELL # | |
# STRINGS # | |
# # | |
# # | |
################################################################################ | |
#------------------------------------------------------------------------------# | |
# | |
# ENCRYPT A STRING WITHIN A SHELL SCRIPT: | |
# | |
# This method enables you to include encrypted elements within a shell script | |
# Elements are entirely secured and public exposure of your script will not | |
# compromise the integrity of that encrypted string in any way. | |
# | |
# USE CASES: | |
# 1) Securing the contents and operations of a script on a shared system | |
# 2) Securing API authorization credentials on public repository files | |
# | |
# ATTRIBUTION: h8rt3rmin8r | |
# EMAIL: 161803398@email.tg | |
# PGP KEY: h8rt3rmin8r.com | |
# | |
#------------------------------------------------------------------------------# | |
# GENERATE A PUBLIC & PRIVATE KEY PAIR WITH OPENSSL | |
openssl genrsa -out rsa_key.pri 2048; openssl rsa -in rsa_key.pri -out rsa_key.pub -outform PEM -pubout | |
# ENCRYPT THE DESIRED PORTIONS OF YOUR SHELL SCRIPT USING THE PUBLIC KEY | |
# This example encrypts the string, "My million-dollar bitcoin master key": | |
$ echo "My million-dollar bitcoin master key" | openssl rsautl -encrypt -inkey rsa_key.pub -pubin -out secret.dat | |
# UNENCRYPT YOUR STRING USING YOUR PRIVATE KEY | |
string=`openssl rsautl -decrypt -inkey rsa_key.pri -in secret.dat `; echo $string | |
# The output of this command will be, "My million-dollar bitcoin master key" | |
#------------------------------------------------------------------------------# | |
# NOTE: If you are performing this operation on a shared computer, take care | |
# to avoid storing the secret key in a location where other system users are | |
# able to access. | |
#------------------------------------------------------------------------------# | |
################################################################################ | |
### ### | |
### "think outside the box" ### | |
### ($) ¯\_(ツ)_/¯ (฿) ### | |
### ### | |
############################### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment