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