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.