views:

76

answers:

2

I am working on a project where we are passing encrypted data between C#, Java and ColdFusion applications. To generate the key and iv for 256 bit AES encryption. I have the following array which I need to convert in ColdFusion 9 to useable key

The Java Code for the Key

new byte[]{
              (byte)172, (byte)181, (byte)241, (byte)21, (byte)129,
              (byte)236, (byte)96, (byte)46, (byte)92, (byte)211, 
              (byte)187, (byte)106, (byte)90,(byte)69, (byte)29,
              (byte)186, (byte)99, (byte)65, (byte)134, (byte)125,
              (byte)218,(byte)117, (byte)9, (byte)223, (byte)13,
              (byte)207, (byte)20, (byte)62, (byte)31,(byte)226, (byte)129, (byte)33
        }

The ColdFusion Code to encrypt (Can't seem to get this to all show up here):

<cfset awsSecret = "[172,181,241,21,129,236,96,46,92,211,187,106,90,69,29,186,99,65,134,125,218,117,9,223,13,207,20,62,31,226,129,33]"


Using .getBytes() and base64 encoding - I also end up with a key that is 113 bytes. Any help would be fantastic!

+2  A: 

One way is to convert the int values to a byte array, then to base64

<cfset ints = [172,181,241,21,129,236,96,46,92,211,187,106,90,69,29,186,99,65,134,125,218,117,9,223,13,207,20,62,31,226,129,33]>
<cfset bytes = []>
<cfloop array="#ints#" index="i">
    <cfset arrayAppend(bytes, javacast("int", i).byteValue())>
</cfloop>
<cfset keyAsBase64 = BinaryEncode(javacast("byte[]", bytes), "base64")>
Leigh