web stats
CryptoJS - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 02-26-2014, 07:42 AM
skekasaurus skekasaurus is offline
OBX.3 Kenobi
 
Join Date: Dec 2013
Posts: 145
skekasaurus is on a distinguished road
Default Decrypt an AES encrypted string

I'm in the need of decrypting a string that was encrypted using AES. I was thinking of using the CryptoJS library (https://code.google.com/p/crypto-js).

Currently struggling with how I can import this into Mirth to be able to use it. The only way I've seen to import external libraries is by

Code:
importPackage(Packages.org.apache.http.client);
tried using the URL between the parentheses but got an error that it doesn't accept http strings. So my question is how can I import this libary? Will I need to make something similar in a java jar and add that in my lib/custom folder?

Any other recommendations of how I can decrypt a string that used AES for encryption are welcomed!

Last edited by skekasaurus; 02-27-2014 at 12:41 PM.
Reply With Quote
  #2  
Old 02-26-2014, 08:00 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,126
narupley is on a distinguished road
Default

You can include it with an External Script step, or if you want it to be included with all channels you can do it with a function code template.
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #3  
Old 02-26-2014, 08:56 AM
skekasaurus skekasaurus is offline
OBX.3 Kenobi
 
Join Date: Dec 2013
Posts: 145
skekasaurus is on a distinguished road
Default

I'll definitely need it available to multiple channels, so a code template will be the way to go. But I'm unsure how exactly to include it. If I download the "aes.js" from http://code.google.com/p/crypto-js/s...rollups/?r=636, do I copy&paste the contents into function field of the code template?
Reply With Quote
  #4  
Old 02-26-2014, 09:01 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,126
narupley is on a distinguished road
Default

Quote:
Originally Posted by skekasaurus View Post
I'll definitely need it available to multiple channels, so a code template will be the way to go. But I'm unsure how exactly to include it. If I download the "aes.js" from http://code.google.com/p/crypto-js/s...rollups/?r=636, do I copy&paste the contents into function field of the code template?
Yep, that should work.
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #5  
Old 02-26-2014, 10:18 AM
skekasaurus skekasaurus is offline
OBX.3 Kenobi
 
Join Date: Dec 2013
Posts: 145
skekasaurus is on a distinguished road
Default

Okay so i got the javascript library as a code template. I know this is probably outside the scope of how far you can assist with 3rd party stuff, but I'm doing a test run of using the code template.

Following this guide: http://code.google.com/p/crypto-js/#AES

I tried encrypting a simple string, map it to a variable and have the filewriter throw it into a text file.

Initially, I did this:

Code:
var x = new CryptoJS;

var encrypted = CryptoJS.AES.encrypt('Message', 'Secret Passphrase');
var decrypted = CryptoJS.AES.decrypt(encrypted, 'Secret Passphrase');

connectorMap.put('test', decrypted);
But I was getting an exception saying that I couldn't do "var x = new CryptoJS;" because it's an object no a function. So i removed that line and the channel successfully wrote to a file, however it outputted the type rather than my string. This is what I got in the file "[object Object]"

Any idea what I might be doing wrong?
Reply With Quote
  #6  
Old 02-26-2014, 10:23 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,126
narupley is on a distinguished road
Default

From the same exact page:

http://code.google.com/p/crypto-js/#The_Cipher_Output

Quote:
The Cipher Output

The plaintext you get back after decryption is a WordArray object. See Hashers' Output for more detail.
http://code.google.com/p/crypto-js/#The_Hasher_Output

Quote:
The Hasher Output

The hash you get back isn't a string yet. It's a WordArray object. When you use a WordArray object in a string context, it's automatically converted to a hex string.

HTML Code:
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/sha256.js"></script>
<script>
    var hash = CryptoJS.SHA256("Message");

    alert(typeof hash); // object

    alert(hash); // 2f77668a9dfbf8d5848b9eeb4a7145ca94c6ed9236e4a773f6dcafa5132b2f91
</script>
You can convert a WordArray object to other formats by explicitly calling the toString method and passing an encoder.

HTML Code:
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/sha256.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js"></script>
<script>
    var hash = CryptoJS.SHA256("Message");

    alert(hash.toString(CryptoJS.enc.Base64)); // L3dmip37+NWEi57rSnFFypTG7ZI25Kdz9tyvpRMrL5E=

    alert(hash.toString(CryptoJS.enc.Latin1)); // /wf�����JqE��6sܯ+/�

    alert(hash.toString(CryptoJS.enc.Hex)); // 2f77668a9dfbf8d5848b9eeb4a7145ca94c6ed9236e4a773f6dcafa5132b2f91
</script>
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #7  
Old 10-14-2014, 07:13 AM
kpatel kpatel is offline
What's HL7?
 
Join Date: Oct 2014
Posts: 5
kpatel is on a distinguished road
Default

I download the "aes.js" from http://code.google.com/p/crypto-js/s...rollups/?r=636, do I copy&paste the contents into function field of the code template but it's not working can you please explain me how to do it.
it's giving error : TypeError: Cannot call method "decrypt" of undefined

Last edited by kpatel; 10-14-2014 at 07:17 AM.
Reply With Quote
  #8  
Old 10-14-2014, 07:16 AM
skekasaurus skekasaurus is offline
OBX.3 Kenobi
 
Join Date: Dec 2013
Posts: 145
skekasaurus is on a distinguished road
Default

Copy the CryptoJS source code, and paste it into a new code template. The type would be function, and I use global as my context.
__________________
Mirth Connect v3.2.2
Java 8
SQL Server 2005
Reply With Quote
  #9  
Old 10-14-2014, 07:23 AM
skekasaurus skekasaurus is offline
OBX.3 Kenobi
 
Join Date: Dec 2013
Posts: 145
skekasaurus is on a distinguished road
Default

Quote:
Originally Posted by kpatel View Post
I download the "aes.js" from http://code.google.com/p/crypto-js/s...rollups/?r=636, do I copy&paste the contents into function field of the code template but it's not working can you please explain me how to do it.
it's giving error : TypeError: Cannot call method "decrypt" of undefined
Can you show how you're trying to use it in your code and where (in preprocessor, transformer, etc.)?
__________________
Mirth Connect v3.2.2
Java 8
SQL Server 2005
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 09:42 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Mirth Corporation