Solved

Java Encryption Called in ColdFusion

Posted on 2014-03-31
6
227 Views
Last Modified: 2014-04-01
Given a new project where I am way out of my depth!   We have keys for encryption that need to be decrypted and then consumed.   This site is built in CF8 and the sample code they sent was in Java.   I have most of it transferred over calling java within CF but this line is stumping me:

byte[] key = Base64.decode(KEY)

Open in new window


How do I use java within CF to call that?
0
Comment
Question by:digitalwise
  • 3
  • 3
6 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 39968149
(Edit) You shouldn't need java just for that. Assuming KEY is a base64 encoded string, use the binaryDecode() function instead. It decodes a string from base64, hex, etc... into bytes:

       <cfset key = binaryDecode( TheBase64KeyStringHere, "base64")>
0
 

Author Comment

by:digitalwise
ID: 39969029
Thank you - that is what I was using but I wasn't getting a result that was usable so I thought maybe I was doing something wrong!
0
 
LVL 52

Expert Comment

by:_agx_
ID: 39969068
Well it should work ok.. but I have heard of slight differences between some base64 algorithms. If you want to try it the pure java way, just make sure the jar containing the "Base64" class in is your CF class path. (You've probably done that already).  Then create an instance of it.  I don't know which library "Base64" is from .. my guess would be Apache Commons, so something like:

 key = createObject("java", "org.apache.commons.codec.binary.Base64").decode(theValue);

Open in new window


If that doesn't work, check the "import" statements at the top of the java examples. They'll tell you the correct path.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:digitalwise
ID: 39969100
I get a Parameter supplied to Base64 decode is not a byte[] error with that.   I just opened another question related to this in its entirety since I am stuck on another spot!   Thanks for looking at it again.
0
 

Author Comment

by:digitalwise
ID: 39969103
0
 
LVL 52

Expert Comment

by:_agx_
ID: 39969528
I get a Parameter supplied to Base64 decode is not a byte[] error with that.

Yeah, I was just guessing that class is from apache commons :) Can't be sure without seeing the java imports.  
       
Though now that I think about it ... CF has an older version of that lib baked in. From the error, it sounds like it doesn't include the "decode(string)" method. So IF that is the library in the java example, you couldn't use that code anyway. Not without jumping through a few hoops ie Either replacing the built in version (*might* break things) or using JavaLoader.cfc.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
array220 challenge 8 45
wordcount challenge 11 74
solarwind tftp server 2 30
Eclipse IDE - Cannot copy/paste from console output 8 62
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

708 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

17 Experts available now in Live!

Get 1:1 Help Now