Encrypt and decrypt a password in shell script

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Encrypt and decrypt a password in shell script
# 1  
Old 02-27-2015
Question Encrypt and decrypt a password in shell script

Hi All,

very good morning all.

I am trying to connect to informatica repository by using shell script.
I have written pmrep connect command in the script file. But i need to provide repository, domain ,username and password to connect. Username and password are hard coded in the script file which is not recommanded. So i tried to encrypt the password and save it in a file. After that i dont know how to use that encrypted password during script file execution.

Can anyone suggest me how to decrypt the password from the file and it needs to be connected to the repository as well. And also provide me the sample script file to understand better.

Thanks in advance....
# 2  
Old 02-27-2015
The method used to encrypt the password, should also be providing way to decrypt it too!?
# 3  
Old 02-27-2015
If i decrypt that password it can be saved in a file. but how can it be used in the script file. I mean, i want to store it in variable insdie script file and it can be used.

my Question is: how to store that decrypted password in a variable . How to assign it to a variable.

For encryption i used below command:
openssl das3 -salt -in file.txt -out file.des3

For decryption i used below command:
openssl das3 -salt -in file.des3 -out file1.txt

if i do with above command the decrypted password will be saved in file1.txt
i want to assign it to variable. and it can be used in my connect command.
is this the way to assign it to variable?
dec_pwd=openssl das3 -salt -in file.des3 -out file1.txt

or any other command to redirect to a variable.
or how can i read the decrypted password from file1.txt

please let me know.
thanks in advance...

Last edited by Scrutinizer; 02-27-2015 at 04:22 AM.. Reason: code tags
# 4  
Old 02-27-2015
Have you checked openssl man pages? there must be some options to to deal with STDIN and STDOUT.

regarding your issue, you can same file content to a variable

var=$(cat file1.txt)

Please note, there must be nothing else in the file except the password
# 5  
Old 02-27-2015
Thanks for your reply clx.
But if i check in file1.txt it contains the normal password i.e not recommonded. So everyone can see my password in the file1.txt .
Actually file.des3 is having encrypted password.
So i am looking for the command which will decrypt the encrypted password from file.des3 and store it in a variable .
So that i can use that variable and can connect to repository.

is it possible?
Please let me know.
All the suggestions are accepted.
# 6  
Old 02-27-2015
Well you can control the file permissions.

Just by chance, can you try removing -out file1.txt part and see if the password is being displaying on the screen.

If yes,

var=$(openssl das3 -salt -in file.des3)

# 7  
Old 02-27-2015
thanks for quick reply.

The command var=$(openssl das3 -salt -in file.des3) is not working because it is prompting for the user credentials in the unix system.
While script file is running in informatica it shouldnot prompt.So it is keep on running and it shouldnot complete.

Any other way to do it.

thanks in advance.

Last edited by Don Cragun; 02-27-2015 at 09:26 AM.. Reason: Add ICODE tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Encrypt and Decrypt a File with Password

Hello, I have few files on unix which are payroll related and I need them to encrypt with password so others wouldn't see the data. I use ETL tool and would like to know the unix command that does encryption/decryption to use in the ETL. Thank you, Sri (3 Replies)
Discussion started by: eskay
3 Replies

2. Shell Programming and Scripting

Encrypt and decrypt the password in a Shell Script

Hello, I have the following UNIX shell script which connects to the teradata database and executes the SQL Queries. For this, I am passing database name, username and password. I don't want to reveal my password to anyone. So, is there any way that I can encrypt my password and read the... (2 Replies)
Discussion started by: ronitreddy
2 Replies

3. Shell Programming and Scripting

Encrypt Password file and decrypt in a shell script

Hi All, I have stored Oracle database passwords in a hidden file - .pass_file. My shell script reads the hidden file, gets the password and then logs in to the Oracle database and runs some SQL script. My requirement is: I need to provide the shell script to be executed by someone else. So,... (1 Reply)
Discussion started by: sunpraveen
1 Replies

4. Shell Programming and Scripting

Encrypt and Decrypt

I have script for all oracle prod db. I have hard coded the username / password. I need a mechanism to encode and decode the username / password in a shell script. Another challenge is I use the username and password in a Select command for oracle DB. How can call the decrypted... (2 Replies)
Discussion started by: ilugopal
2 Replies

5. Shell Programming and Scripting

Bash Script to decrypt encrypt log and archive

Hi Please see if you have come across any aprts of this. I can read, integrate and syntehsixe. Any help you could offer me would be super. thanks in advance! Good day. Thank you for your response in this matter. Here are some further details: 1) scripting is to be in BASH... (1 Reply)
Discussion started by: cdc01
1 Replies

6. Shell Programming and Scripting

how to encrypt a password in shell script

Hi, I have run the below script which is connected to db2 v9.5. There is no issue. The only problem is how to encrypt the dbpwd? #!/bin/ksh #---- Set Environment dbalias="dev1db" dbuser="user1" dbpwd="password" #---- Connect to the Database cd /opt/ibm/db2/V9.5/bin db2 "connect to... (1 Reply)
Discussion started by: lookinginfo
1 Replies

7. Shell Programming and Scripting

how to set password/encrypt a shell script

Hi, I have written a shell script in unix for my customer. Now I want to make it only execute and not to read/write. Can anybody help me how to set password protect/encript my script. Thanks Suresh (3 Replies)
Discussion started by: suresh3566
3 Replies

8. Shell Programming and Scripting

How to encrypt and decrypt a file

How to encrypt and decrypt a file using unix Command? Can any one help me? (2 Replies)
Discussion started by: laknar
2 Replies

9. Shell Programming and Scripting

Encrypt and Decrypt script

Dear Experts, I am using one script name :volume.sh and its written in bash shell script. I just want to encrypt the script so that any one else cannot see it. please tell me the commands how to encrypt the script as well as to decrypt it. Regards, SHARY (9 Replies)
Discussion started by: shary
9 Replies

10. Shell Programming and Scripting

encrypt and decrypt password

how do i encrypt and decrypt a password (2 Replies)
Discussion started by: sanwish
2 Replies
Login or Register to Ask a Question

Featured Tech Videos