String encryption and decryption


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting String encryption and decryption
# 1  
Old 08-19-2012
Question String encryption and decryption

Hello All,

There are so many questions on this and I didn't find any concluded answer.

I want to encrypt a string in the script, actually this is a password. I tried using openssl (I am a newbie to openssl), but it is generating a long one which we can't remember.

I want to encrypt the password and want to share it, so users can use that and my script needs to decrypt when the users enter it.

Any solutions, where I can generate small passwords (or equal length of original).

Thanks!

AIX 5.3
# 2  
Old 08-19-2012
First off, putting passwords in scripts is a VERY BAD idea. It doesn't matter if they are encrypted or not, because having the password in clear text for all to read is just a small part of the problem, The bigger problem is that passwords are likely to change over time and you will have to change the script (and probably several scripts, if you employ that mechanism more often) every time. Chances are you forget on of these scripts and this will only surface in the moment you need it least.

Another thing is, that, regardless of how you encrypt the password, all the tools necessary to decrypt it are on the system already, therefore, it doesn't matter if you put it there in clear text or encrypted. Suppose your password is encrypted with the /some/encryption utility and will decrypted with the /some/decryption utility. You encrypt the password, get some value and have now a line in your script looking like

Code:
/do/something -pw=$(/some/decryption <encrypted-PW>)

If i want to know the password and only have your script, what would prevent me from taking the encypted value from your script and issue

Code:
/some/decryption <encrypted-PW>

at the command line to get the unencrypted password myself?

If you do the decryption on the remote machine the problem stays the same: i will send the encrypted version and the remote system will decrypt it itself, so that the encrypted form of the password becomes the effective PW.

So, after this lengthy explanation of why this will not work in any way what will work?

Let us first rephrase the requirement: Something should be done at remote system X as user X. User A on the local system should initiate that using a script.

Now.create a user B at your local system. establish a line of trust between this user B and user X at the remote host by exchanging ssh-keys. User B(local) can now log on as user X(remote) without any password.

Now give the ownership of your script to this user B(local) and make it executable only for this user. User B would now be able to run this script and do the remote part without any password through the SSH-mechanism.

Now set up a sudo permission for User A(local) to run the script as user B(local). This way User A is not required to know the password for neither user B nor the remote system. He will still not be able to do anything else than run this script (sudo will prevent that).

Disable logging in for user B(local) so that nobody can misuse the line of trust established between user B(local) and user X(remote).

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 3  
Old 08-19-2012
crypt can hide your password, but makes binary. Compression hardens the data for encryption, but makes short strings long. To make it friendly text, you can pass that to an encoder like uuencode or base64: Man Page for base64 (OpenSolaris Section 1) - The UNIX and Linux Forums .
Code:
$ echo user_password | crypt master_password | od -xc     
0000000    6e1f    c36b    9569    bfd2    5264    d224    8031
          n 037 303   k 225   i 277 322   R   d 322   $ 200   1
0000016
 
$ user_pw_enc=$( echo user_password | crypt master_password | base64 )
$ user_pw_dec=$( echo user_pw_enc | base64 -d | crypt master_password )
$

# 4  
Old 08-19-2012
Quote:
Originally Posted by karumudi7
Hello All,

There are so many questions on this and I didn't find any concluded answer.

I want to encrypt a string in the script, actually this is a password.
The answer is, simply, "don't do that".

If you can retrieve a password, so can a hacker. There's no point.

Never, ever keep around retrievably-stored passwords if you can possibly help it. Not even the OS does that, for its login system.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 08-19-2012
Quote:
Originally Posted by DGPickett
crypt can hide your password, but makes binary.
Unfortunately, I don't have crypt.
# 6  
Old 08-24-2012
There are many free clones of crypt: crypt open source code - Google Search

Make sure you are putting the master password and user passwords in secure places. All apps and systems have their hidden secrets and keys. This may be a good place for Public/Private Key Encryption. Lots written about the security challenges of any authentication system. Authentication is often that the encrypted trial password matches the encrypted stored password, so every raw password is only a transient memory artifact in automatic variables.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Gpg (GnuPG) encryption and decryption

Hi Friends, There are some 7 years script in out linux server. I am trying to understand them since Linux Server changed(A). Below line in one of the encrypting script. Here scenario is encrypting bank files in our (A) server and doing Secure Copy to Server (B). GPG -v --batch --yes --armor... (1 Reply)
Discussion started by: johnsnow
1 Replies

2. Cybersecurity

File encryption tools with MAC address as an encryption key

Hi all, I'm looking for secure file encryption tools that use MAC address as encryption key. FYI, I'm using Red Hat Enterprise Linux OS. For example: when A wants to send file to B A will encrypt the file with B's computer MAC/IP address as an encryption key This file can only be decrypted... (2 Replies)
Discussion started by: sergionicosta
2 Replies

3. Shell Programming and Scripting

auto encryption and decryption of files during log in and log off

we r to develope a project which involves automatic encryption of all the text files user was working upon during logg off and to decrypt them during log on this is to be done by writing a shell script can anyone help (2 Replies)
Discussion started by: vyom
2 Replies

4. Ubuntu

help regarding encryption and decryption of files on linux

we are to develope a project on linux whose aim is to automatically encrypt files after logoff and to decrypt them using password after log in this is to be made by chging source code of linux ........... can any one help me on this???? (1 Reply)
Discussion started by: vyom
1 Replies

5. UNIX for Dummies Questions & Answers

Identify a file for encryption or decryption

Dear Members, Can we find if a particular file is encrypted or decrypted. I need a command by which i should be able to identify if a file is encrypted or decrypted. How can we do this? (1 Reply)
Discussion started by: sandeep_1105
1 Replies

6. Solaris

encryption & decryption functions in sun solaries

hi, is there any library functions available in sun solaries for encryption and decryption functions. regards suresh (1 Reply)
Discussion started by: suresh_rtp
1 Replies

7. Solaris

PGP encryption/decryption solaris 9

Hi Someone is going to send me a file that they have encrypted by PGP encryption on windows pc to my solaris 9 server. They will give me the pgp key to decrypt the file. How can I do this on solaris 9 Is there a tool installed by default to decrypt or do I need to install something to... (0 Replies)
Discussion started by: frustrated1
0 Replies

8. Programming

Password encryption/decryption in flat-text files

Dear all, If anyone has some ideas for me how to tackle the following situation: Imagine a type of client-server application. The client application is started by a human operator with all the necessary LDAP/Kerberos in place. The server application is started automatically as a daemon process.... (2 Replies)
Discussion started by: domivv
2 Replies

9. UNIX for Dummies Questions & Answers

File Encryption and Decryption in UNIX.

Hello guys ! I have used "crypt <first> second" command to encrypt "first" to "second" file. i have assign a key for that of course. Now when i try to look content of "seocnd" file through "cat second" command, the file is encrypted and cannot be read which is according to plan. But when... (3 Replies)
Discussion started by: abidmalik
3 Replies
Login or Register to Ask a Question