469,275 Members | 1,569 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

Java CryptoAPI 3DES Key Compatibility

Hi,

A Java application is encrypting a block of text using 3DES ECB mode
and PKCS5 padding. I need to decrypt this text using C#. I've
extracted the 192 bit key using the getEncoded() method of the
SecretKey Java class. However when I use this key in .NET i cannot
decrypt the cipher text.

I am pretty sure that all my settings are correct, as far as setting
the ECB mode, PKCS5 padding and converting the cipher text to byte
arrays. I think it's the key that is giving me problems. Is there
anything that I must do to the exported java key before I use it in
..NET ?

Thanks
Michael Bebenita
Nov 15 '05 #1
3 7465
"Michael Bebenita" <th*******@sbcglobal.net> wrote in message
news:82**************************@posting.google.c om...

A Java application is encrypting a block of text using 3DES ECB mode
and PKCS5 padding. I need to decrypt this text using C#. I've
extracted the 192 bit key using the getEncoded() method of the
SecretKey Java class. However when I use this key in .NET i cannot
decrypt the cipher text.

I am pretty sure that all my settings are correct, as far as setting
the ECB mode, PKCS5 padding and converting the cipher text to byte
arrays. I think it's the key that is giving me problems. Is there
anything that I must do to the exported java key before I use it in
.NET ?


AFAIK, Java provides you with a 192-bit parity-adjusted key and .NET
requires a 168-bit non-parity-adjusted key. I don't think there is any
function in Java or .NET to remove the parity but it's simple enough to
implement (just a case of removing the LSB of each byte in the key).

You also need to ensure that your IV is shared between the two applications.

HTH

--
Gerard John Krupa BSc AMBCS
Purveyor of network management software
http://www.bogbrushzone.co.uk/
Nov 15 '05 #2
"Gerard Krupa" <ge****@spamfreebogbrush-zone.co.uk> wrote in message news:<dh*************@newsfep1-gui.server.ntli.net>...
"Michael Bebenita" <th*******@sbcglobal.net> wrote in message
news:82**************************@posting.google.c om...

A Java application is encrypting a block of text using 3DES ECB mode
and PKCS5 padding. I need to decrypt this text using C#. I've
extracted the 192 bit key using the getEncoded() method of the
SecretKey Java class. However when I use this key in .NET i cannot
decrypt the cipher text.

I am pretty sure that all my settings are correct, as far as setting
the ECB mode, PKCS5 padding and converting the cipher text to byte
arrays. I think it's the key that is giving me problems. Is there
anything that I must do to the exported java key before I use it in
.NET ?


AFAIK, Java provides you with a 192-bit parity-adjusted key and .NET
requires a 168-bit non-parity-adjusted key. I don't think there is any
function in Java or .NET to remove the parity but it's simple enough to
implement (just a case of removing the LSB of each byte in the key).

You also need to ensure that your IV is shared between the two applications.

HTH


Thanks for the reply,

I tired extracting the 168 bit key by removing the parity bit. However
now I get a "Specified key is not a valid size for this algorithm."
exception when i try to use the key. I remember reading somewhere that
..NET / Crypto API igonore the parity bit anyways.

Michael
Nov 15 '05 #3
th*******@sbcglobal.net (Michael Bebenita) wrote in message news:<82**************************@posting.google. com>...
"Gerard Krupa" <ge****@spamfreebogbrush-zone.co.uk> wrote in message news:<dh*************@newsfep1-gui.server.ntli.net>...
"Michael Bebenita" <th*******@sbcglobal.net> wrote in message
news:82**************************@posting.google.c om...

A Java application is encrypting a block of text using 3DES ECB mode
and PKCS5 padding. I need to decrypt this text using C#. I've
extracted the 192 bit key using the getEncoded() method of the
SecretKey Java class. However when I use this key in .NET i cannot
decrypt the cipher text.

I am pretty sure that all my settings are correct, as far as setting
the ECB mode, PKCS5 padding and converting the cipher text to byte
arrays. I think it's the key that is giving me problems. Is there
anything that I must do to the exported java key before I use it in
.NET ?


AFAIK, Java provides you with a 192-bit parity-adjusted key and .NET
requires a 168-bit non-parity-adjusted key. I don't think there is any
function in Java or .NET to remove the parity but it's simple enough to
implement (just a case of removing the LSB of each byte in the key).

You also need to ensure that your IV is shared between the two applications.

HTH


Thanks for the reply,

I tired extracting the 168 bit key by removing the parity bit. However
now I get a "Specified key is not a valid size for this algorithm."
exception when i try to use the key. I remember reading somewhere that
.NET / Crypto API igonore the parity bit anyways.

Michael


Forget all that, there was no compatibility problem. The error had to
do with something unrelated.
Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Jez Naisbitt | last post: by
reply views Thread by Kim HM | last post: by
3 posts views Thread by Simang | last post: by
reply views Thread by Frederic ESNOUF \(MVP-ISA\) | last post: by
reply views Thread by =?Utf-8?B?VmVuZWRpY3Q=?= | last post: by
1 post views Thread by tshad | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.