By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,600 Members | 1,683 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,600 IT Pros & Developers. It's quick & easy.

Abount DESCryptoServiceProvider

P: n/a
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!

Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
wolf <a@b.c> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2

P: n/a
> > 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.


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!
Nov 16 '05 #3

P: n/a
wolf <a@b.c> wrote:
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.


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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.