Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Encrypt values from a file on HP-UX 3

Status
Not open for further replies.

zephan

Programmer
Jan 14, 2002
217
A2
Hi everyone,
I have a standard installation of HP-UX (11). I have got a file containing a list of values. I need a script that pops a value from the file, encrypt it, and push it in another file.
What RSA features can I find in HP-UX, what are the command names and syntax ? If no RSA is there, are they another standard command to encrypt/decrypt a single alphanumeric string which is passed as an argument ?
Have you got such script :) ? If no I will be happy with RSA command :)
Regards,
Zephan
 
OpenSSL is freely available and will encrypt and decrypt in almost any cipher or encoding you can imagine. Look at the openssl enc command.

Annihilannic.
 
Thank you guy. Have you got an idea on how to crypt every single line independantly ?
 
Also see the "[tt]crypt[/tt]" command for simple file encryptions.

man crypt


 
Even crypt doesn't do the job :
Suppose the file cleartext with the content below
value1
value2
value3
....

I want to get the file ciphertext with the following content :
encryptedvalue1
encryptedvalue2
encryptedvalue3

Etc.
 
Even crypt doesn't do the job
Really ? What about something like this ?
crypt YourPasswordHere < cleartext > ciphertext

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Sorry for the confusion, opensll do a lot of things and as Sam stated, crypt provides simple functions. The man page for crypt states "If two or more files encrypted with the same key are concatenated and an attempt is made to decrypt the result, only the the first of the original files is decrypted correctly."

It means I will be only able to decrypt my first value. I want to keep values crypted independantly so I can pull as many values as I want later on.
Regards
 
Crypt generates binary, without a one-one correspondance on the lines or EOL. One could pass each crypt output to uuencode and save it via a script, like this:

$ more cryptit
#!/bin/sh
num=1
while read line
do
echo $line | crypt password | uuencode line$num >> /tmp/output
num=`expr $num + 1`
done

where output looks like:

$ more output
begin 644 line1
#J)9I

end
begin 644 line2
&--FOBM8B

end
begin 644 line3
&-#S#ZL B

end
begin 644 line4
#VC-I

end
begin 644 line5
(441$$6&GV ,

end

To decode, pass the begin/end pair thorough a pipe to
| uudecode -p | crypt password

I know, clunky but one could write a nice wrappper around it.





 
A similar solution using OpenSSL with Base64 encoding:

Code:
$ cat input
one
two
three
$ while read line ; do echo $line | openssl enc -des -base64 -pass pass:KenSentMe ; done < input > output
$ cat output
U2FsdGVkX1+ngxCnjqgILpnf0KSW4ysu
U2FsdGVkX1+o0txc6Rb2S3QWONNKlBdV
U2FsdGVkX1+L2RuXuN1fgC2sl2AmE9pL
$ while read line ; do echo $line | openssl enc -d -des -base64 -pass pass:KenSentMe ; done < output
one
two
three
$

You may want to consider storing the password in some other more secure way though, or prompting for it!

Annihilannic.
 
Well, that be even better, give you a star Anni.
I could probably do the single line thing with the crypt library and some C code, but using existing commands, much, much betta!
 
Anni, do you like circular references ? Please take a look on thread759-1472004 it is a technological challenge for me.
Regards,
Zephan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top