Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Security / August 2007

Tip: Looking for answers? Try searching our database.

Envryption interop between .NET and java

Thread view: 
elh.maayan@gmail.com - 29 Aug 2007 16:48 GMT
hi..
we have an application in dotnet that should encrypt a string in
dotnet and send it to a java application (both application web but
both need credentrial to get in, so the password will be encrypted in
dotnet side sent as URL paramter to the other java webapp where it
willl be decrypted and used)

so as a test i'm trying to create acode in dotnet and code in java
that should encrypt the same string and produce the same encrypted
byte array, in dotnet:

        string plainText = "This is a test";
          byte[] keySalt = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16 };

           byte[] input = Encoding.Default.GetBytes(plainText);
           Console.WriteLine(getBytes(input));

           // INIT the CIPHER and key
           RijndaelManaged AesCipher = new
RijndaelManaged();

           AesCipher.Key = keySalt;

           // init vector, don't know what that is, otherwise the
array is always different
           AesCipher.IV = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16 };
           ICryptoTransform crypt = AesCipher.CreateEncryptor();

           // ENCRYPT
           byte[] cipherText =crypt.TransformFinalBlock(input, 0,
input.Length);

           Console.WriteLine(getBytes(cipherText));

in java

               String msg="This is a test";
      byte[] keySalt=new byte[]{1, 2, 3, 4, 5, 6,7, 8, 9,10, 11, 12, 13,
14, 15, 16};

      byte[] input=msg.getBytes();
      System.out.println(getBytes(input));

      // INIT the CIPHER and key

      Cipher aesChiper=Cipher.getInstance("AES");
      Key key=new SecretKeySpec(keySalt,"AES");
      aesChiper.init(Cipher.ENCRYPT_MODE,key);

      // ENCRYPT
      byte[] encBytes=  aesChiper.doFinal(msg.getBytes());

      System.out.println(getBytes(encBytes));

but the array in both platform comes out differently..
why?
elh.maayan@gmail.com - 29 Aug 2007 17:33 GMT
i got it, in java init the IV goes like this:

      IvParameterSpec spec=new IvParameterSpec(new byte[] { 0,0, 0, 0,
0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0 });
      AlgorithmParameters prm=AlgorithmParameters.getInstance("AES");
      prm.init(spec);

Cipher aesChiper=Cipher.getInstance("AES/CBC/PKCS5Padding");

      Key key=new SecretKeySpec(keySalt,"AES");
      aesChiper.init(Cipher.ENCRYPT_MODE,key,prm);

2nd, and here is the kicker:
bytes in dotnet are unsigned while in java are signed.. bummers so i
had to convert one of them ..
On Aug 29, 6:48 pm, elh.maa...@gmail.com wrote:
> hi..
> we have an application in dotnet that should encrypt a string in
[quoted text clipped - 54 lines]
> but the array in both platform comes out differently..
> why?


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.