• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

How to select specificied parts of a file to decrypt

 
Ranch Hand
Posts: 43
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi JavaRanch,

My recent work involved encrypting sensitive information while logging. It was for a Interactive Voice Response (IVR) application where users would enter User IDs and Passwords and they needed to be masked. It will be decrypted in a UI by people who have access to key.

With a lot of help from Coderanch and by doing a bit of tweaking of the application files and log4j files, I was able to bring about encryption successfully.

This is how my log file would look:

TIME STAMP [DEBUG] Caller ANI 4447478375
TIME STAMP [DEBUG] DNIS 1540
TIME STAMP [INFO] Main menu message played to caller
TIME STAMP [DEBUG] Option 1 selected
TIME STAMP [INFO] Recharge menu message played to caller
TIME STAMP [INFO] Caller initiates DTMF feed for UserID
TIME STAMP [DEBUG] UserID entered: <Encrypted> `5¿JZ[üÈv€ ò`º*€• ÂÈ"W% \Q±(X
‹s[⚃3\0ƒ‡h?ƒ«~ú=ÒÂ#íø"QnGpØfDT
¡b@éBA>«†$™±5VIlJ*pX݃Rƒj
</Encrypted>
TIME STAMP [INFO] Caller initiates DTMF feed for Password
TIME STAMP [DEBUG] Password entered: <Encrypted> `5¿JZ[üÈv€ ò`º*€• ÂÈ"W% \Q±(X
‹s[⚃3\0ƒ‡h?ƒ«~ú=ÒÂ#íø"QnGpØfDT
¡b@éBA>«†$™±5VIlJ*pX݃Rƒj
</Encrypted>
TIME STAMP [INFO] Transaction successful
TIME STAMP [INFO] Caller disconnects

Now my problem comes up with debugging. I need to select the entire text between <Encrypted> </Encrypted> (I appended these tags while encryption, thinking that it might help me to locate the source text for decryption). I thought of selecting the text between these tags, pass it to a decryption and replace it with the decrypted text.

I tried a couple of options to select the text between the tags and neither of them were fruitful.
1) I tried using a SAX parser implementation, but got a couple of SAXParseExceptions since the log file does not have a well defined Tag structure that an XML file should have.
2) I tried using a Regex - Pattern and Matcher to locate the text, I could not make a match for the tags, since the encrypted text contains newlines and I could only feed one line at a time by the below expression.
pattern.Matcher(in.readLine());
As you can see, the encrypted text spans many lines and reading one line at a time, could not make a match for the tags.
3) One other option yet to be tried was to read the whole file, character by character and look for a match. But the process would affect the performance and it a tedious one to code too.

Please help me out as I am new to java.

Thanks,
Vimal.

 
Bartender
Posts: 7488
171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

2) I tried using a Regex - Pattern and Matcher to locate the text, I could not make a match for the tags, since the encrypted text contains newlines and I could only feed one line at a time by the below expression.
pattern.Matcher(in.readLine());
As you can see, the encrypted text spans many lines and reading one line at a time, could not make a match for the tags.


Regexps have no problem dealing with multiline text; check the Pattern.compile(String, int) method and the Pattern.MULTILINE flag. The problem is that encrypted data is binary, not text, so retrieving it after it has been stored in a text file is problematic, to say the least. You should convert it to text (using something like base-64 encoding) before writing it to the log file; that would also result in a string that fits on a single line, thus handling the multi-line issue.

3) One other option yet to be tried was to read the whole file, character by character and look for a match. But the process would affect the performance and it a tedious one to code too.


It may be slower, but the relevant question is: would it be too slow? No way to tell until you try. And I sure hope you weren't serious about the last part of that sentence; it can't possibly be more than 10 lines of code you're talking about.
 
My honeysuckle is blooming this year! Now to fertilize this tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic