I can share a few bits for sure (there is a lot of code to paste
here!):
We have a test Salt:
byte[] salt = new byte[8];
salt[0] = Byte.valueOf("0").byteValue();
salt[1] = Byte.valueOf("0").byteValue();
salt[2] = Byte.valueOf("0").byteValue();
salt[3] = Byte.valueOf("0").byteValue();
salt[4] = Byte.valueOf("0").byteValue();
salt[5] = Byte.valueOf("0").byteValue();
salt[6] = Byte.valueOf("0").byteValue();
salt[7] = Byte.valueOf("0").byteValue();
and a pass to the key initialisation (in a byte array) the value
HereIsATestString (same string as the CF example)
Iterations are set to the same value as well.
The meat of the encryption is in these lines which initialise the
factory
PBEParameterSpec ps = new
javax.crypto.spec.PBEParameterSpec(salt,
iterations);
SecretKeyFactory kf =
SecretKeyFactory.getInstance("PBEWithMD5AndDES");
SecretKey k = kf.generateSecret(new
javax.crypto.spec.PBEKeySpec(pass));
encryptCipher =
Cipher.getInstance("PBEWithMD5AndDES/CBC/
PKCS5Padding");
encryptCipher.init(Cipher.ENCRYPT_MODE, k, ps);
and this method which does the encryption:
public synchronized String encrypt(String str)
throws SecurityException
{
try
{
byte[] utf8 = str.getBytes("UTF8");
byte[] enc = encryptCipher.doFinal(utf8);
return Base64.encodeBytes(enc);
}
catch (Exception e)
{
throw new SecurityException("Could not encrypt:
" +
e.getMessage());
}
}
On Dec 7, 2:53 pm, Andy Wu <[email protected]> wrote:
> Lawrence,
>
> Would you happen to have the code for the java applet? That would
> certainly help in determining what we're doing differently.
>
> Thanks
> Andy
>
> On 07/12/2011 09:51, Loz wrote:
>
>
>
>
>
>
>
> > The salt is the same per the snippet i included:
>
> > salt = BinaryDecode("0000000000000000","hex");
>
> > Will sort the iterations test and alternate encoding now... back soon!
>
> > thanks
> > LAwrence
>
> > On Dec 7, 1:48 pm, Alex Skinner<[email protected]> wrote:
> >> Please provide
>
> >> 1. The value of salt on both platforms
>
> >> 2. Please give us the output on both where iterations = 1
>
> >> 3. Please give us a test case with alternate encoding and algorithms
>
> >> This will allow us to isolate whether these differences are occurring
> >> whether it is purely the algorithm or something else
>
> >> Thanks
>
> >> Alex
>
> >> On 7 December 2011 12:56, Loz<[email protected]> wrote:
>
> >>> Hi,
> >>> I am almost through converting our CF8 client facing applications to
> >>> use OBD 1.5 (we will get to 2.0 as soon as this is on its feet!)
> >>> I am seeing inconsistent encrypt results when i compare the CF8 and
> >>> OBD results from the following code:
> >>> <cfscript>
> >>> stringToEncrypt = "HereIsATestString";
> >>> algorithm = "PBEWithMD5AndDES";
> >>> encoding = "base64";
> >>> iterations = 592;
> >>> salt = BinaryDecode("0000000000000000","hex");
> >>> passPhrase = "18065E360D64BCC0551AD5C06C3C3DA9";
> >>> </cfscript>
> >>> <cfset encString = Encrypt(variables.stringToEncrypt,
> >>> variables.passPhrase, variables.algorithm, variables.encoding,
> >>> variables.salt, variables.iterations)>
> >>> <cfoutput>encryptedString = #variables.encString#</cfoutput><br/>
> >>> On CF8: encryptedString = IikBTt8qSAKXhJr/1rRZZ4JNg68+K1HU
> >>> On OBD: encryptedString = 4esc4qAmQVAXFS7SgWCQW5Ve1WeXn+PK
> >>> The CF8 output gives the same output as a separate Java Applet I use
> >>> that runs the same encryption algorithm.
> >>> Any ideas why OBD output is different from CF8 and the Java Applet?
> >>> This is the last bit of the puzzle to my migration!
> >>> Cheers
> >>> Lawrence
> >>> --
> >>> online documentation:http://openbd.org/manual/
> >>> google+ hints/tips:https://plus.google.com/115990347459711259462
> >>> http://groups.google.com/group/openbd?hl=en
> >> --
> >> Alex Skinner
> >> Managing Director
> >> Pixl8 Interactive
>
> >> Tel: +448452600726
> >> Email: [email protected]
> >> Web: pixl8.co.uk
--
online documentation: http://openbd.org/manual/
google+ hints/tips: https://plus.google.com/115990347459711259462
http://groups.google.com/group/openbd?hl=en