I am translating the key we have into bytes. This is the code written in Java:
DESKeySpec desKeySpec = new DESKeySpec(epsKey.getBytes());
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ETYPE);
SecretKey key = keyFactory.generateSecret(desKeySpec);
ecipher = Cipher.getInstance(ETYPE);
dcipher = Cipher.getInstance(ETYPE);
ecipher.init(Cipher.ENCRYPT_MODE, key);
dcipher.init(Cipher.DECRYPT_MODE, key);
And this is the code to decrypt:
byte[] dec = new BASE64Decoder().decodeBuffer(encodedStr);
byte[] utf8 = dcipher.doFinal(dec);
String decryptedStr = new String(utf8, "UTF8");
What would be the C# equivalent of handling all this? There is no
equivalent in C# of the SecretKeyFactory class, unfortunately.
"Jon Skeet [C# MVP]" wrote:
> Carolyn Vo <(E-Mail Removed)> wrote:
> > Hi there! I have a string that was encrypted in Java using the classes
> > DESKeySpec, SecretKeyFactory, SecretKey, and Cipher. It looks like using the
> > SecretKeyFactory puts a transparent layer on top of the bytes from our key so
> > when I try to decrypt using the classes in C#, I get different and invalid
> > data. Has anyone ever been able to decrypt in C# what was originally
> > decrypted in Java? I've read the samples from Frank Fang but they don't
> > work.
>
> Well, encryption generally works on bytes rather than strings - have
> you managed to decrypt the *bytes* to the same bytes which ended up
> being encrypted in Java?
>
> --
> Jon Skeet - <(E-Mail Removed)>
> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too
>