I am looking for how to encrypt a string of Strings in linux for later use in other scripts through environment variables, I want to do something similar to powershell where:
# Se convierte el password recibido como texto plano en SecureString
$SecureString = convertto-securestring -AsPlainText -Force -String "M1P@ssw0rd"
# Se convierte el SecureString en una cadena estandar cifrada que se puede guardar para su posterior uso
$StandardString = ConvertFrom-SecureString $SecureString
# Se guarda la cadena estandar cifrada en una variable de entorno
[Environment]::SetEnvironmentVariable("passq", "$StandardString", "Machine")
# Se guarda el contenido encriptado de la variable de entorno en una nueva variable
$variable = [Environment]::GetEnvironmentVariable("passq", "Machine")
# Se hace un reverso de la cadena estandar cifrada a SecureString
$passwordencry = ConvertTo-SecureString -String $variable
# Se realiza la reconversión de SecureString a texto plano
$passwordencry = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($passwordencry)
$passwordencry = [Runtime.InteropServices.Marshal]::PtrToStringBSTR($passwordencry)
You can use PowerShell from Linux.
I share the documentation to install PowerShell on Linux https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-linux?view=powershell-7.2
Another option is using the OpenSSL library, for example:
encode.sh
decode.sh
make executable files
encryption example
decryption example
I found this solution here --> https://stackoverflow.com/questions/33718005/how-to-encrypt-and-decrypt-a-string-text-in-shell-linux-environment
I hope this helps!