Jeffry Houser's Blog - ASCrypt3https://www.jeffryhouser.com/index.cfm
Jeffry Houser's Blogen-usMon, 19 Nov 2018 16:57:24 -0700Tue, 16 Feb 2016 09:00:00 -0700BlogCFChttp://blogs.law.harvard.edu/tech/rssjhblog@farcryfly.comjhblog@farcryfly.comJeffry Houserjhblog@farcryfly.comJeffry HouserJeffry Houser's Bloghttps://www.jeffryhouser.com/index.cfm
noHow can I avoid Cross Domain Restrictions When doing HTML5 Development?https://www.jeffryhouser.com/index.cfm/2016/2/16/How-can-I-avoid-Cross-Domain-Restrictions-When-doing-HTML5-Development
Sometimes when I'm developing an HTML5 app for a client it does not make sense to set up the client's full environment on my local machine.
Sometimes the setup is complicated and the budget doesn't allow me to spend a day or two for setup. Sometimes the apps are leveraging services that spread between multiple departments and servers and it is not practical to set them all up locally. Other times, the client wants me up and running in the shortest order possible. In such situations, I still write code on my local local machine, but access their services remotely.
HTML applications that run in a browser this can cause a problem. The HTML app can't use xmlHTTPRequest to make calls to remote servers. This is done to prevent normal users from running into cross site scripting which are often used for nefarious means.
When developing code locally, however, my use is legit and I need a temporary work around. In these situations, I often go to a a Chrome command line argument that disables cross site scripting restrictions:
<code>
pathtoChromeInstall\Chrome.exe -disable-web-security
</code>
Once this is in place, I am able to run HTML code on my local server that can make remote service calls to my client's server. Then all is good in the world and I'm able to continue to work productively with my client.
There is a great <a href="http://stackoverflow.com/questions/3102819/disable-same-origin-policy-in-chrome">StackOverflow writeup on this point</a>.
JavaScriptProfessionalASCrypt3Tue, 16 Feb 2016 09:00:00 -0700https://www.jeffryhouser.com/index.cfm/2016/2/16/How-can-I-avoid-Cross-Domain-Restrictions-When-doing-HTML5-Developmentinfo@theflexshow.com (Jeffry Houser and John Wilker)Encrypt in Flex and Decrypt in ColdFusionhttps://www.jeffryhouser.com/index.cfm/2007/12/6/Encrypt-in-Flex-and-Decrypt-in-ColdFusion
<a href="http://tech.groups.yahoo.com/group/flexcoders/message/95663">A thread</a> has been going on for a bit today over on the <A href="http://tech.groups.yahoo.com/group/flexcoders">Flex Coders</a> list. How do you encrypt data in Flex, pass it to ColdFusion and then decrypt it? I struggled with this very same question quite a while ago; and sort of came up with an answer after a lot of trial and error. This post is me finally documenting my answer.
First, there are two open source AS3 libraries that you can use to deal with data encryption in Flex: <A href="http://ascrypt3.riaforge.com">ASCrypt3</a> and <a href="http://crypto.hurlant.com/">Crypto</a>. ASCrypt3 was my attempt at converting an ActionSCript 2 library to an ActionScript 3 code base. I understand that Crypto was created from the ground up to make use of AS3 enhancements to make things more performant. Both libraries offer plenty of ways to encrypt, or decrypt data in Flex.
I'm going to assume that we want to use <a href="http://en.wikipedia.org/wiki/Advanced_Encryption_Standard">AES (Rijndael)</a> to encrypt the data in Flex before sending it to ColdFusion. Unfortunately, I was never able to get the ASCrypt3 code base working with CF properly. People have told me they've used it succesfully for Java. I have used Crypto to succesfully pass encrypted data back and forth between ColdFusion and Flex, though.
First we need to create our key, and specify some settings. Load the <a href="http://crypto.hurlant.com/demo/">Crypto demo</a>. Click "Secret Key" from the TabNavigator and set these steps:
<ol>
<li><strong>Encryption</strong>: AES</li>
<li><strong>Mode</strong>: ECB</li>
<li><strong>Padding</strong>PKCS#5</li>
<li><strong>Prepend IV to Cipher</strong>: Leave Unchecked</li>
<li><strong>Key Format:</strong>Hex </li>
<li><strong>Plain Text</strong>: Text</li>
<li><strong>Cipher Text</strong>: Hex</li>
</ol>
Once your settings are set, click "Generate 128 bits" to generate a key. If you create your own key using alternate means, that's fie but you'll have to be sure it is 128 bits and in Hex format; or things may go awry when switching between systems.
Type your text: "This is a Test", then click the Encrypt button. Doing this on the fly, my key was "e1787cfc32d25355f267c53837c6062e" and the cipher text was "182f2031903e0a63ed77881b1561954c".
I'll assume you know of some manner to get this data from Flex to ColdFusion (or, really any other backed you desire).
On the ColdFusion side, there is a great <A href="http://kb.adobe.com/selfservice/viewContent.do?externalId=e546373d&sliceId=1">knowledge base article</a> about dealing with encryption, so you might want to start there. To decrypt, we are dealing with a handful of built in functions:
<ul>
<li><A href="http://www.cfquickdocs.com/?getDoc=BinaryDecode"><strong>BinaryDecode</strong></a>: Converts a string to a binary object. We use it to turn our Hex Key into binary format.</li>
<li><A href="http://www.cfquickdocs.com/?getDoc=ToBase64"><strong>ToBase64</strong></a>: This calculates a string representation of a binary object. We are using BinaryDecode to turn our Binary String Hex Key into a string.</li>
<li><a href="http://www.cfquickdocs.com/?getDoc=Decrypt"><strong>Decrypt</strong></a>: This one performs the decryption algorithm</li>
</ul>
The actual code will be something like his:
<code>
<cfset HexKey = "e1787cfc32d25355f267c53837c6062e">
<cfset myKey = ToBase64(BinaryDecode(HexKey, "Hex"))>
<cfset Encrypted = "182f2031903e0a63ed77881b1561954c">
<Cfset Decrypted = Decrypt( Encrypted, MyKey, 'AES','Hex')>
</code>
First we take the HexKey, binaryDecode it and Base64 it. Then we feed those values along with our encrypted text into the Decrypt function. Finally, output the results:
<code>
<cfoutput>
#decrypted#
</cfoutput>
</code>
There is a lot of conversion going on, but I'm not quite sure why it's needed. I was able to get this working using Crypto and CF, but never ASCrypt3 and CF. I suspect the problem was in the encoding of the key + result; but never had a chance to explore it in further depth. Can anyone explain?
Your mission, if you choose to accept it is to write the CF code to encrypt data before sending it to Flex. It shouldn't take long.
If you need do something 'real world' you'll have to download Crypto and figure out how to call the encryption algorithms within Flex. :-)
ProfessionalASCrypt3FlexColdFusionThu, 06 Dec 2007 12:30:00 -0700https://www.jeffryhouser.com/index.cfm/2007/12/6/Encrypt-in-Flex-and-Decrypt-in-ColdFusioninfo@theflexshow.com (Jeffry Houser and John Wilker)ASCrypt3 Rijndael Updatehttps://www.jeffryhouser.com/index.cfm/2007/1/10/ASCrypt3-Rijndael-Update
I made an update to Rijndael encryption in ASCrypt. There was a problem initializing the object if you were using a blocksize or key length other than the default.
It should be working better now. Of course, I still can't get it to produce the same results as ColdFusion's Encrypt function. [More]
ProfessionalASCrypt3FlexWed, 10 Jan 2007 12:33:00 -0700https://www.jeffryhouser.com/index.cfm/2007/1/10/ASCrypt3-Rijndael-Updateinfo@theflexshow.com (Jeffry Houser and John Wilker)ASCrypt3 code works in Flex 2.0.1https://www.jeffryhouser.com/index.cfm/2007/1/9/ASCrypt3-code-works-in-Flex-201
I just did some testing of ASCrypt3 in Flex 2.0.1. Everything seems to be working as expected.
The allusive LZW script started throwing an error (as opposed to returning no results and just not working). Aside from that, I still wasn't able to get it working.
However, I did go back to one of the <a href="http://www.razorberry.com/blog/archives/2004/08/22/lzw-compression-methods-in-as2/">sources</a> used for the ASCrypt LZW class. I was able to get the source working ( I named it LZW_RazorBerry ). The interesting thing about this implementation is that it allows you to output an XML safe string.
I added this to the readme (once I update the file), but I felt the need to say that I never verified any of the algorithms, only converted them. I am not an encryption expert.
<b>Update</b> File updated, you can download <a href="http://ascrypt3.riaforge.org/">here</a>
ProfessionalASCrypt3FlexTue, 09 Jan 2007 17:47:00 -0700https://www.jeffryhouser.com/index.cfm/2007/1/9/ASCrypt3-code-works-in-Flex-201info@theflexshow.com (Jeffry Houser and John Wilker)ASCrypt 3.0 now on RIAForgehttps://www.jeffryhouser.com/index.cfm/2006/12/8/ASCrypt-30-now-on-RIAForge
I've been creating an ActionScript 3 port of the ASCrypt ActionScript 2 component. The project is now up on RIAForge.
<A href="http://ASCrypt3.riaforge.org">http://ASCrypt3.riaforge.org</a>
You'll find my first conversion attempt (Rijndael) in the software pod to the right. Behind the scenes, I've converted everything in the initial ASCrypt component except for LZW which I can't get to work.
I'm still in the process of uploading files and the sort.
<b>Update</b>: I've now uploaded the files to RIAForge!
<b>Update</b>: And changed the link in my software pod!
ProfessionalASCrypt3FlexFri, 08 Dec 2006 11:51:00 -0700https://www.jeffryhouser.com/index.cfm/2006/12/8/ASCrypt-30-now-on-RIAForgeinfo@theflexshow.com (Jeffry Houser and John Wilker)