当我创建一个WebClient来使用一些RESTful xml时,我可以通过两种方式指定unicode编码:
WebClient wc = new WebClient ();
wc.Encoding = Encoding.UTF8;
wc.Encoding = UTF8Encoding.UTF8;
Run Code Online (Sandbox Code Playgroud)
哪个更正/更好?
任何人都可以让我知道我在这段代码中犯了什么错误?此代码是用C#.NET编写的.我需要编写一个使用C#.NET使用base64格式编码字符串的算法,然后使用PHP使用base64_decode()进行解码.请看下面的snippit:
System.Security.Cryptography.RijndaelManaged rijndaelCipher = new System.Security.Cryptography.RijndaelManaged();
rijndaelCipher.Mode = System.Security.Cryptography.CipherMode.CBC;
rijndaelCipher.Padding = System.Security.Cryptography.PaddingMode.Zeros;
rijndaelCipher.KeySize = 256;
rijndaelCipher.BlockSize = 128;
byte[] pwdBytes = System.Text.Encoding.UTF8.GetBytes(_key);
byte[] keyBytes = new byte[16];
int len = pwdBytes.Length;
if (len > keyBytes.Length) len = keyBytes.Length;
System.Array.Copy(pwdBytes, keyBytes, len);
rijndaelCipher.Key = keyBytes;
rijndaelCipher.IV = keyBytes;
System.Security.Cryptography.ICryptoTransform transform = rijndaelCipher.CreateEncryptor();
byte[] plainText = Encoding.UTF8.GetBytes(unencryptedString);
byte[] cipherBytes = transform.TransformFinalBlock(plainText, 0, plainText.Length);
return Convert.ToBase64String(cipherBytes);
Run Code Online (Sandbox Code Playgroud)