Using sed with special characters produced from crypto


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Using sed with special characters produced from crypto
# 1  
Old 08-19-2011
Using sed with special characters produced from crypto

Hey there,

I'm facing some weird issues with sed when trying to do substitution in a text file with the content of some environment variables. Those variables are used to store crypted (3DES) info with much special characters and that's where the problem starts.

I've already tried to use both weak and strong quotes to protect the content of the variables (and \ to protect characters) passed to sed but I still get truncated values injected instead of the whole thing :S (well actually I've identified the $!@^¤ character in cause and guess what it seems like it's a ETX character so end of text).

Has anyone a clue or a solution to get over this? Smilie

Last edited by Jormun; 08-19-2011 at 05:39 PM..
# 2  
Old 08-19-2011
Please supply an example.
# 3  
Old 08-19-2011
That'll have to way til monday. The ETX character was the last one I had to deal with before I stopped and I'm almost sure I'll face the same problem with some other control characters.
# 4  
Old 08-19-2011
Raw encrypted data is going to be raw bytes without regard to representation. I don't think you can expect to keep such data in shell variables raw, NULLS and things which just can't be represented as an ASCII string will mess it up. Even if you somehow got them in, you'll have real trouble passing them to anything else.

In what way do they need to be used?

Code:
$ echo asdf > file
$ openssl base64 < file
YXNkZgo=
$ echo "YXNkZgo=" | openssl enc -d base64
asdf
$

You could pipe the data from a file into openssl base64 to get safe base64-encoded data(which is always representable in ASCII) to store in your shell variables, then get the binary data back later from it and pipe it where it needs to go.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 08-20-2011
Thanks for the reply Corona688, I'll give it a try.

I actually have to store that encrypted data in shell vars which looks like ok the way I did. As you stated above the problem is then to pass that data to other scripts as the non representable characters make sed go nuts :S

I just hope openssl is available on the system I'm working on.

Once again thank you for the hint Smilie

##########################
EDIT:

I've tried to encode / decode with base64 and it seems to work fine (100.000 auto generated values of 20 characters used in my tests). I can provide java code template for those who might be interested.

Thanks Apache for commons-codec-1.5.jar

Last edited by Jormun; 08-20-2011 at 08:46 AM.. Reason: Solution tested
# 6  
Old 08-21-2011
Quote:
Originally Posted by Jormun
I just hope openssl is available on the system I'm working on.
Should be available on nearly all Linux systems. Other places may have different commands to handle base64.
# 7  
Old 08-23-2011
Well I'm working on a AIX system with much restrictions so I'm not so sure it'll be available. Anyway I worked around it with some apache lib. Thx again for the hint Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed in a while loop with special characters

I have the foolowing data file: File1 <p name="A">5004</p> <p name="B">5004</p> <p name="C">5004</p> <p name="A">15004</p> <p name="B">15004</p> <p name="C">15004</p> In a while loop using sed (100 of line need to be replace), I need the output to File3:... (2 Replies)
Discussion started by: bobo
2 Replies

2. Shell Programming and Scripting

Sed - remove special characters

Hi, I have a file with this line, it's always in the first line: I want to remove these special characters: ´╗┐ file1 ´╗┐\\bar\c$\test2\;3.348.118 Bytes;160 ;3 \\bar\c$\test\;35 Bytes;2 ;1 I want the same file to be only \\bar\c$\test2\;3.348.118 Bytes;160 ;3 \\bar\c$\test\;35... (4 Replies)
Discussion started by: nakaedu
4 Replies

3. Shell Programming and Scripting

sed special characters issue

Hi I'm trying to replace string1 by string2 in file homepage.htm as follows but is not working. Please Help: sedsed -i "s@'://your server name:port/test/owa'@'://11.22.33.44:5555/pls/SAMPLE'@g" homepage.htm Where, String1 ://your server name:port/test/owa String2... (3 Replies)
Discussion started by: koazter
3 Replies

4. Shell Programming and Scripting

Need help with sed to escape special characters

Hello Everyone, I need to read an encrypted password from the user and update that value in an xml file. I am trying to use "sed" for searching the appropriate tag and replacing this new value that get from the user. Since the encrypted password can contain special characters(like /,\,&,etc),... (4 Replies)
Discussion started by: majose
4 Replies

5. Shell Programming and Scripting

SED with Special characters

Hello All Seeking the right one SED command. My attempt is: From orginal.txt by SED to target.txt sed -i "/('outbound-callerid/a\$ext->add($context, $exten, '', new ext_SipAddHeader('P-Preferred-Identity', '<sip:${CALLERID(nummer)}@carrier.com>'));" orginal.txtWhat am make wrong?:wall: ... (5 Replies)
Discussion started by: mdbinder
5 Replies

6. Shell Programming and Scripting

sed with many special characters

I started with this: counter1=1 cp file.txt file_${counter1}.tmp while read name1 do echo $name1 counter2=`expr $counter1 + 1` sed /'${name1}'/d file_${counter1}.txt > file_${counter2}.txt counter1=`expr $counter1 + 1` done < source.txtsource.txt contains the... (1 Reply)
Discussion started by: lakanino
1 Replies

7. Shell Programming and Scripting

sed with special characters

Hi, I am reading a file (GC_JAR.log) which has entries like: 511725.629, 0.1122672 secs] 525268.975, 0.1240036 secs] 527181.835, 0.2068215 secs] 527914.287, 0.2884801 secs] 528457.134, 0.2548725 secs] I want to replace all the entries of "secs]" with just "secs" Thus, the output... (4 Replies)
Discussion started by: itzz.me
4 Replies

8. Shell Programming and Scripting

SED with Wildcards and Special Characters

Hi All, Need you guys' help to achieve the following: I have some strings and i wish to threw off the end part that's in the file path. From: /directoryname1/subdirectoryname1/abc.txt /directoryname2/subdirectoryname2/defggf.txt To: /directoryname1/subdirectoryname1/... (7 Replies)
Discussion started by: Radeon
7 Replies

9. Shell Programming and Scripting

Changing Special Characters Using Sed

Hi. Does anyone know how to use the sed command to change the special border characters on this .per file. I have to edit about 80 .per files. I need a sed script to change the below 3 and A characters. ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ Test Islands, Office of Public Health -- WIC... (4 Replies)
Discussion started by: cstovall
4 Replies

10. Shell Programming and Scripting

awk/sed with special characters

i have this script that searches for a pattern. However it fails if the pattern includes some special characters. So far, it fails with the following strings: 1. -Cr 2. $Mj 3. H'412 would a sed or awk be more effective? i don't want the users to put the (\) during the search (they... (5 Replies)
Discussion started by: apalex
5 Replies
Login or Register to Ask a Question