Re: Envryption interop between .NET and java



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...@xxxxxxxxx wrote:
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?


.



Relevant Pages

  • Envryption interop between .NET and java
    ... dotnet and send it to a java application (both application web but ... dotnet side sent as URL paramter to the other java webapp where it ... that should encrypt the same string and produce the same encrypted ...
    (comp.lang.java.security)
  • Re: Moving On
    ... you're travelling. ... If MS had invented Java ... dotNet is for high-bandwidth intra-nets and for backend internet ... It is tailor made for intra-office business suites. ...
    (microsoft.public.vb.general.discussion)
  • is dotnet right for my requirements?
    ... I'm new to dotnet. ... Ability to run on a desktop with no internet (stand-alone, ... go with Java and use their webstart technology to accomodate this. ... there's an easy way to go from a vb.net app to an asp.net app? ...
    (microsoft.public.dotnet.general)
  • Re: OpenQM vs. Everything Else
    ... As you rightly say, Dawn, with dotnet - and with technologies such as Java, ... about Java can be written on the back of a small stamp with room to spare... ... If what a VAR or developer is offering to a prospective client isn't ... Taking an anti-MS ...
    (comp.databases.pick)
  • Re: Will VC++ face out ?
    ... Can C# support standard or Win32 C/C++ class lib dll and COM? ... Can dotnet and Java do device IO control with drivers? ...
    (microsoft.public.dotnet.languages.vc)