Solved

Automate SHA-256 process

Posted on 2013-05-30
6
563 Views
Last Modified: 2013-05-31
We have an XML file which is produced weekly.
Within that file are the tags <BACSHashCode>characterstring</BACSHashCode>

The tags appear multiple times within the XML file and the character string differs within each occurrence.

I need to be able to encrypt each character string occurrence with a SHA-256 encrypted version. I am doing this manually at present using an online facility. I copy the value of each 'character string' from the file into conversion facility and paste back the result overriding the previous character string.

It is a very lengthy and error-prone process.

Does anyone know of a utility which will automate this process?

I guess I would need to feed it the file name, or open the file within the utility. Then I would need to give it the name of the tags and it would do the job for me.

Thanks for any suggestions.
0
Comment
Question by:RichardWalsh
  • 4
  • 2
6 Comments
 
LVL 25

Accepted Solution

by:
clockwatcher earned 500 total points
ID: 39206906
If you have perl available to you (or can install it).  It's a one-liner:

perl -i.bak -ne 'BEGIN { use Digest::SHA qw(sha256_hex); } s#<BACSHashCode>(.*?)</BACSHashCode>#qq(<BACSHashCode>).sha256_hex($1).qq(</BACSHashCode>)#ge; print;' myfile.xml

The above would make a backup of the file called myfile.xml called myfile.xml.bak and in-place edit the original file (myfile.xml) swapping out all instances of <BACSHashCode>whateverr</BACSHashCode> with the SHA256 version.  I wrote it windows friendly, so it should work under both windows and *nixes.  Just change the single quotes to double quotes on windows.  Windows version:

perl -i.bak -ne "BEGIN { use Digest::SHA qw(sha256_hex); } s#<BACSHashCode>(.*?)</BACSHashCode>#qq(<BACSHashCode>).sha256_hex($1).qq(</BACSHashCode>)#ge; print;" myfile.xml
 
An example of its use:
markh@wheeze:~> cat myfile.xml
<data>
   <element>
      <atag>whatever</atag>
      <BACSHashCode>hello there</BACSHashCode>
    </element>
   <element>
      <atag>another element</atag>
      <BACSHashCode>more data</BACSHashCode>
    </element>
</data>

markh@wheeze:~> perl -i.bak -ne 'BEGIN { use Digest::SHA qw(sha256_hex); } s#<BACSHashCode>(.*?)</BACSHashCode>#qq(<BACSHashCode>).sha256_hex($1).qq(</BACSHashCode>)#ge; print;' myfile.xml 
markh@wheeze:~> cat myfile.xml
<data>
   <element>
      <atag>whatever</atag>
      <BACSHashCode>12998c017066eb0d2a70b94e6ed3192985855ce390f321bbdb832022888bd251</BACSHashCode>
    </element>
   <element>
      <atag>another element</atag>
      <BACSHashCode>737165b08ad9b72940af2167aae90fb7eb3b52faf641c0590d36f857adbe451d</BACSHashCode>
    </element>
</data>

Open in new window

0
 

Author Comment

by:RichardWalsh
ID: 39206952
Many thanks for your very quick response.  I am out today but will try it out this evening and let you know how it goes.
Richard
0
 

Author Comment

by:RichardWalsh
ID: 39209271
I downloaded Perl to my Windows laptop and your solution worked first time!

I am SO grateful for this. The (old) version of the programming language I am using (Progress/Openedge) does not support SHA-256 - although the latest versions do support it.
So we were going to have to manually generate the values in several files weekly.

Your program has made the job MUCH simpler.

Thanks a million.
Richard Walsh
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 25

Expert Comment

by:clockwatcher
ID: 39209904
No problem.  Glad to have been of help.  Funny that you mention Progress.  We actually just implemented a system called QAD that sits atop a Progress/OpenEdge system and I've got to get up to speed with programming in Progress.
0
 

Author Comment

by:RichardWalsh
ID: 39211811
I know of QAD...... I believe it's a big system. If my memory is correct the company was started by a woman and it made her the wealthiest (or one of the wealthiest) women the software world has produced.

If you've not come across Progress before I think you'll be surprised how capable the 4GL is (now called ABL I think).

Progress has always had a reputation for being technically very competent and very profitable but preferring 'stealth marketing' compared with people like Oracle etc.

Good luck and thanks again.
0
 

Author Closing Comment

by:RichardWalsh
ID: 39211818
This solution really went 'the extra mile' in providing a worked example of how to use the program. It has helped me enormously.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
CrytoWall Decryption Error 7 82
PHP - Should Salt be stored in a database or code? 5 70
Whats the use of master secret 4 55
HELP!  Encrypted data on client's laptop 8 56
#SSL #TLS #Citrix #HTTPS #PKI #Compliance #Certificate #Encryption #StoreFront #Web Interface #Citrix XenApp
Encryption for Business Encryption (https://en.wikipedia.org/wiki/Encryption) ensures the safety of our data when sending emails. In most cases, to read an encrypted email you must enter a secret key that will enable you to decrypt the email. T…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A simple description of email encryption using a secure portal service. This is one of the choices offered by The Email Laundry for email encryption. The other choices are pdf encryption which creates an encrypted pdf of your email and any attachmen…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now