Java encryption <--> .NET encryption

  • Follow


Hajo,
I need to exchange encypted data between
..NET and Java environments. The first
problem I encountered is that symmetric
ciphers in .NET needs initialization
vector and Java counterparts don't.

Can some one point me out the place
where I can find any practise and
patterns for encrypted communication
between Java and .NET ?

thanks for any info

Gawel
0
Reply gawel 3/16/2005 11:58:45 AM

A bit of discussion and some sample code for this for 3DES case:
   http://www.jensign.com/JavaScience/dotnet/NetDESEncrypt
- Mitch Gallant

"gawel" <gawelek@gazetamoveitout.pl> wrote in message news:d1978h$mo0$1@nemesis.news.tpi.pl...
> Hajo,
> I need to exchange encypted data between
> .NET and Java environments. The first
> problem I encountered is that symmetric
> ciphers in .NET needs initialization
> vector and Java counterparts don't.
>
> Can some one point me out the place
> where I can find any practise and
> patterns for encrypted communication
> between Java and .NET ?
>
> thanks for any info
>
> Gawel


0
Reply Michel 3/16/2005 1:14:39 PM


Michel Gallant wrote:

> A bit of discussion and some sample code for this for 3DES case:
>    http://www.jensign.com/JavaScience/dotnet/NetDESEncrypt

At first glance looks great. Thanks for it.
Did you do similar comparison with RSA ?


Gawel
0
Reply gawel 3/16/2005 3:15:28 PM

One more thing.
In this article you mentioned that RSA
is not in JCE. But here I see RSA:
http://java.sun.com/j2se/1.4.2/docs/guide/security/jce/JCERefGuide.html#AppA


Can you explain me whre is the truth :)


Gawel
0
Reply gawel 3/16/2005 3:49:24 PM

Pre JSE 1.5  RSA was only available for digital signature (not for encryption/enveloping).
However, provider was updated in JSE 1.5 to include RSA encryption capability:
    http://java.sun.com/j2se/1.5.0/docs/guide/security/enhancements15.html

- Mitch Gallant

"gawel" <gawelek@gazetamoveitout.pl> wrote in message news:d19kov$82t$1@nemesis.news.tpi.pl...
> One more thing.
> In this article you mentioned that RSA
> is not in JCE. But here I see RSA:
> http://java.sun.com/j2se/1.4.2/docs/guide/security/jce/JCERefGuide.html#AppA
>
>
> Can you explain me whre is the truth :)
>
>
> Gawel


0
Reply Michel 3/16/2005 7:38:06 PM

http://www.jensign.com/JavaScience/dotnet/RSAEncrypt
- Mitch

"gawel" <gawelek@gazetamoveitout.pl> wrote in message news:d19ipe$nun$1@nemesis.news.tpi.pl...
> Michel Gallant wrote:
>
> > A bit of discussion and some sample code for this for 3DES case:
> >    http://www.jensign.com/JavaScience/dotnet/NetDESEncrypt
>
> At first glance looks great. Thanks for it.
> Did you do similar comparison with RSA ?
>
>
> Gawel


0
Reply Michel 3/16/2005 7:38:40 PM

Michel Gallant wrote:
> A bit of discussion and some sample code for this for 3DES case:
>    http://www.jensign.com/JavaScience/dotnet/NetDESEncrypt

I implemented AES using your pattern and all works great
except 256 bit keys. In this case I got exception about
not supported key length and in documentation is written
that JCE implementation of AES suppoerts 128, 192 and
256 bit keys.

One more thing, you can add to your article that
decrypted .NET bytes needs to be converted into String in Java
using following statement:

string plainDotNetText = new String(decryptedBytes, "UTF-16LE");


thanks once again for help


Gawel
0
Reply gawel 3/17/2005 2:39:43 PM

Michel Gallant wrote:
> http://www.jensign.com/JavaScience/dotnet/RSAEncrypt

Hajo,

have you ever exchange RSA public key using Base64 between
Java and .NET? I have no problem with exchanging of
symmertic key(AES, DES) but for RSA I got modulus can
not be negative exception. I think it is connected with bytes
order but I do not know what is going on.



regards


Gawel
0
Reply gawel 3/18/2005 2:02:19 PM

gawel wrote:

> Michel Gallant wrote:
> 
>> http://www.jensign.com/JavaScience/dotnet/RSAEncrypt
> 
> 
> Hajo,
> 
> have you ever exchange RSA public key using Base64 between
> Java and .NET? I have no problem with exchanging of
> symmertic key(AES, DES) but for RSA I got modulus can
> not be negative exception. I think it is connected with bytes
> order but I do not know what is going on.

I found the reason of problem.
I have 1024 bit RSA. Modulus in java
has 129 bits and privateExponnet has 129 bits
but in .NET modulus has 128 bits and private exponent
has 128 bits. Java adds leading 0 to modulus and privateExponent.
When you add this 0 all is ok. Can you explain it ?


regards

Gawel
0
Reply gawel 3/18/2005 2:28:01 PM

Shouldn't be a problem .. after all Modulus is simply a number and
same with exponent. That extra 0 is a leading 0 in Big Endian number
so has no significance. If you are careless with interpreting your bits
in swapping from little to big Endian .. it could cause a problem.
I think that "artifact" is documented in some of my C# source code  :-)
- Mitch

"gawel" <gawelek@gazetamoveitout.pl> wrote in message news:d1eooe$e6s$1@nemesis.news.tpi.pl...
> gawel wrote:
>
> > Michel Gallant wrote:
> >
> >> http://www.jensign.com/JavaScience/dotnet/RSAEncrypt
> >
> >
> > Hajo,
> >
> > have you ever exchange RSA public key using Base64 between
> > Java and .NET? I have no problem with exchanging of
> > symmertic key(AES, DES) but for RSA I got modulus can
> > not be negative exception. I think it is connected with bytes
> > order but I do not know what is going on.
>
> I found the reason of problem.
> I have 1024 bit RSA. Modulus in java
> has 129 bits and privateExponnet has 129 bits
> but in .NET modulus has 128 bits and private exponent
> has 128 bits. Java adds leading 0 to modulus and privateExponent.
> When you add this 0 all is ok. Can you explain it ?
>
>
> regards
>
> Gawel


0
Reply Michel 3/18/2005 3:43:02 PM

Hajo,

Michel Gallant wrote:
> Shouldn't be a problem .. after all Modulus is simply a number and
> same with exponent. That extra 0 is a leading 0 in Big Endian number
> so has no significance. 
if you encode base64 key then it has :)

>If you are careless with interpreting your bits
> in swapping from little to big Endian .. it could cause a problem.
> I think that "artifact" is documented in some of my C# source code  :-)

Exactlly but in context of .NET and CryptoAPI.

Gawel


wrote:
>>
>>
>>>Michel Gallant wrote:
>>>
>>>
>>>>http://www.jensign.com/JavaScience/dotnet/RSAEncrypt
>>>
>>>
>>>Hajo,
>>>
>>>have you ever exchange RSA public key using Base64 between
>>>Java and .NET? I have no problem with exchanging of
>>>symmertic key(AES, DES) but for RSA I got modulus can
>>>not be negative exception. I think it is connected with bytes
>>>order but I do not know what is going on.
>>
>>I found the reason of problem.
>>I have 1024 bit RSA. Modulus in java
>>has 129 bits and privateExponnet has 129 bits
>>but in .NET modulus has 128 bits and private exponent
>>has 128 bits. Java adds leading 0 to modulus and privateExponent.
>>When you add this 0 all is ok. Can you explain it ?
>>
>>
>>regards
>>
>>Gawel
> 
> 
> 
0
Reply gawel 3/21/2005 10:26:29 AM

10 Replies
321 Views

(page loaded in 0.118 seconds)

Similiar Articles:













7/21/2012 10:27:48 PM


Reply: