4

Encrypt and decrypt a string in shell

 2 years ago
source link: http://www.donghao.org/2021/10/07/encrypt-and-decrypt-a-string-in-shell/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Encrypt and decrypt a string in shell

When using a container in Kubernetes, I prefer to use a shell command to complete the task instead of writing a python script since the shell commands are usually much simpler and intuitive.

If I want to encrypt a string “helloworld”, it could be accomplished by:

echo helloworld | openssl aes-256-cbc -a -salt -pbkdf2 -pass pass:mypassword
Python
xxxxxxxxxx
echo helloworld | openssl aes-256-cbc -a -salt -pbkdf2 -pass pass:mypassword

The ‘mypassword’ is the real password for encryption.

To decrypt, I could just use

echo U2FsdGVkX1+SWVzJK6Ji7DJ77r/U9XxyxNqDXrxZ6ck= | openssl aes-256-cbc -d -a -pbkdf2 -pass pass:mypassword
Python
xxxxxxxxxx
echo U2FsdGVkX1+SWVzJK6Ji7DJ77r/U9XxyxNqDXrxZ6ck= | openssl aes-256-cbc -d -a -pbkdf2 -pass pass:mypassword

Like this:

Loading...

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK