Abount DESCryptoServiceProvider

W

wolf

Can I de-crypt the data by java which is crypt by DESCryptoServiceProvider?

The following is my code to crypt data:
string text = "This is My source data";
byte[] source = System.Text.Encoding.Unicode.GetBytes(text);

DESCryptoServiceProvider des = new DESCryptoServiceProvider();
des.Key = this.key;
des.IV = this.iv;

ICryptoTransform desencrypt = des.CreateEncryptor();
System.IO.MemoryStream ms = new System.IO.MemoryStream();
CryptoStream cryptostream = new
CryptoStream(ms,desencrypt,CryptoStreamMode.Write);

cryptostream.Write(source, 0, source.Length);

byte[] result = ms.ToArray();
cryptostream.Close();
ms.Close();

And then, I will send the release data(result) to other host via http
connection. And the remote host platform is java. Could the java platform
decrypt the data I sent to?

Thanks!
 
J

Jon Skeet [C# MVP]

wolf said:
Can I de-crypt the data by java which is crypt by
DESCryptoServiceProvider?

Yes, you should be able to.
The following is my code to crypt data:
string text = "This is My source data";
byte[] source = System.Text.Encoding.Unicode.GetBytes(text);

DESCryptoServiceProvider des = new DESCryptoServiceProvider();
des.Key = this.key;
des.IV = this.iv;

ICryptoTransform desencrypt = des.CreateEncryptor();
System.IO.MemoryStream ms = new System.IO.MemoryStream();
CryptoStream cryptostream = new
CryptoStream(ms,desencrypt,CryptoStreamMode.Write);

cryptostream.Write(source, 0, source.Length);

byte[] result = ms.ToArray();
cryptostream.Close();
ms.Close();

You've got a problem here - you're not calling
cryptoStream.FlushFinalBlock or Close before you're calling ms.ToArray.
I'd suggest calling cryptoStream.Close, then ms.Close if you want to
(you don't need to) and then ms.ToArray.
And then, I will send the release data(result) to other host via http
connection. And the remote host platform is java. Could the java platform
decrypt the data I sent to?

That should be fine, yes.
 
W

wolf

And then, I will send the release data(result) to other host via http
That should be fine, yes.

Thank you for your replay!
But my goal is to decrypt these code in java. The java lib had provide some
classes for decription, but I can set the key parameter only, the IV
parameter is readonly and it's default value is null!

Thank you!
 
J

Jon Skeet [C# MVP]

wolf said:
Thank you for your replay!
But my goal is to decrypt these code in java. The java lib had provide some
classes for decription, but I can set the key parameter only, the IV
parameter is readonly and it's default value is null!

It sounds like this is really a Java question rather than a .NET
question then. I suggest you ask on one of the Java newsgroups, such as
comp.lang.java.programmer.

I suspect the
Cipher.init(int opmode, Key key, AlgorithmParameters params)
method is what you're after though.
 

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

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top