HighTechTalks DotNet Forums  

Abount DESCryptoServiceProvider

Dotnet FAQs microsoft.public.dotnet.faqs


Discuss Abount DESCryptoServiceProvider in the Dotnet FAQs forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
wolf
 
Posts: n/a

Default Abount DESCryptoServiceProvider - 03-20-2005 , 11:01 PM






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!






Reply With Quote
  #2  
Old   
Jon Skeet [C# MVP]
 
Posts: n/a

Default Re: Abount DESCryptoServiceProvider - 03-21-2005 , 01:30 AM






wolf <a@b.c> wrote:
Quote:
Can I de-crypt the data by java which is crypt by
DESCryptoServiceProvider?
Yes, you should be able to.

Quote:
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.

Quote:
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 - <skeet (AT) pobox (DOT) com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Reply With Quote
  #3  
Old   
wolf
 
Posts: n/a

Default Re: Abount DESCryptoServiceProvider - 03-21-2005 , 02:27 AM



Quote:
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!




Reply With Quote
  #4  
Old   
Jon Skeet [C# MVP]
 
Posts: n/a

Default Re: Abount DESCryptoServiceProvider - 03-21-2005 , 01:13 PM



wolf <a@b.c> wrote:
Quote:
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 - <skeet (AT) pobox (DOT) com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.