2

My output that I have to match is from Java DESede using a BouncyCastle Jar from 2005 ... I am very close...

Here is my output in Java (which is correct) followed by my output in C# ... if you view in an editor, you will see they ALMOST match, except in C# where it has a forward slash "/" in Java it has "%2F", "%2D" and at the end where C# has is an "=" , Java has "%3D". Any ideas? (I added spaces to show they match up - but you will only see them in an editor.)

F3e8sdZ%2F951IRiguIAVqfDLyWptqlbWik5tvFzItcxJCEmupzD9wXp%2BDzIbrf2J2dPpXyEXL2QU%3D (Java - Correct)

F3e8sdZ/ 951IRiguIAVqfDLyWptqlbWik5tvFzItcxJCEmupzD9wXp+ DzIbrf2J2dPpXyEXL2QU= (C# - Close?)

Here is my C# Code:

public static string DoubleTrippleDESede(string strToEncode, ref string symKey, ref ICryptoTransform cipher)
    {
        try
        {
            //byte[] input = Encoding.UTF8.GetBytes("DESede (3DES) Encryption in RAILO CFML");
            byte[] input = Encoding.UTF8.GetBytes(strToEncode);
            //byte[] key = Convert.FromBase64String("ru8femXhTm9jwdGdhb/4Sw==");
            byte[] key = Convert.FromBase64String(symKey);
            TripleDESCryptoServiceProvider algorithm = new TripleDESCryptoServiceProvider();
            algorithm.Mode = CipherMode.ECB;
            algorithm.BlockSize = 64;
            algorithm.KeySize = 192; // 24 byte key
            algorithm.Key = key; //Original
            //algorithm.Key = key.CopyTo(algorithm.Key,)
            cipher = algorithm.CreateEncryptor();
            byte[] encrypted = cipher.TransformFinalBlock(input, 0, input.Length);
            Debug.WriteLine("encrypted (.NET): {0}", Convert.ToBase64String(encrypted));
            return Convert.ToBase64String(encrypted);
        }
        catch (Exception ex)
        {
            return ex.Message;
        } 
    }

Any guidance would be greatly appreciated!!!! I've been at this for 2 weeks and finally can taste victory (I think!?)

Community
  • 1
  • 1
Danimal111
  • 1,976
  • 25
  • 31
  • 2
    It appears that the Java output has been urlencoded. I *think* you could call `System.Uri.EscapeDataString()` to match. – Elliott Frisch Nov 01 '16 at 22:46
  • You're so right... so when I encode it, I get the following F3e8sdZ%2f951IRiguIAVqfDLyWptqlbWik5tvFzItcxJCEmupzD9wXp%2bDzIbrf2J2dPpXyEXL2QU%3d -- notice theo only difference is that the Java "%2F" becomes "%2f" (lowercase f) ... could this present a problem? – Danimal111 Nov 01 '16 at 22:51
  • 1
    "%2F" is "/" and "%2D" is "=", remove the Encodiing. – zaph Nov 01 '16 at 22:54
  • 1
    Of corse 3DES should not be used in new code and should be transitioned to AES in old. – zaph Nov 01 '16 at 22:55
  • 1
    @DanB Many things *could* present a problem, I try to focus on the present. If you're concerned about it, uppercase the encoded result when it differs from input. – Elliott Frisch Nov 01 '16 at 22:56
  • @zaph - It's a 3rd party... I have no control over the other end... I just have to connect into it... – Danimal111 Nov 01 '16 at 22:57
  • 2
    Yeah, I know, it's the same old story. I guess we will be using 3DES in legacy systems in 2050. – zaph Nov 01 '16 at 23:00
  • @ElliottFrisch - Put that down as an answer and I'll give you credit... Thanks! Do you know about Asymmetric Encryption? cause that's step 2... I have it creating a string, but it's wrong... grrrrr... anyway.. please keep an eye out for my next ticket... it'll be here in moments... – Danimal111 Nov 01 '16 at 23:30

1 Answers1

1

Your Java output appears to have additionally been urlencoded. You should be able to call System.Uri.EscapeDataString() to match your present output.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249