PC Review


Reply
Thread Tools Rate Thread

Abount DESCryptoServiceProvider

 
 
wolf
Guest
Posts: n/a
 
      21st Mar 2005
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
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      21st Mar 2005
wolf <(E-Mail Removed)> 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 - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
wolf
Guest
Posts: n/a
 
      21st Mar 2005
> > 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
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      21st Mar 2005
wolf <(E-Mail Removed)> 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 - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA-run-through stopping after abount 250 items =?Utf-8?B?QWxsYW4=?= Microsoft Outlook VBA Programming 6 26th Sep 2006 10:04 PM
Help! abount the webbrowser! zhangyl Microsoft VB .NET 0 7th Mar 2006 08:12 AM
Abount DESCryptoServiceProvider wolf Microsoft Dot NET Framework 3 21st Mar 2005 06:13 PM
Question abount .NET Utada P.W. SIU Microsoft C# .NET 5 28th Jan 2005 03:42 PM
Question abount sent items Mary Microsoft Outlook 0 9th Aug 2004 12:19 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:21 PM.