Java CryptoAPI 3DES Key Compatibility

  • Thread starter Michael Bebenita
  • Start date
M

Michael Bebenita

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
 
G

Gerard Krupa

Michael Bebenita said:
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
 
M

Michael Bebenita

Gerard Krupa said:
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
 
M

Michael Bebenita

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top