472,097 Members | 1,058 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,097 software developers and data experts.

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 7662
"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
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.