what is it mean and it's output?
Can any one please let me know what is it mean and it's output? it is a .Net script.
private static readonly byte[] Key = {
0xda, 0x3c, 0x35, 0x6f, 0xbd, 0xd, 0x87, 0xf0,
0x9a, 0x7, 0x6d, 0xab, 0x7e, 0x82, 0x36, 0xa,
0x1a, 0x5a, 0x77, 0xfe, 0x74, 0xf3, 0x7f, 0xa8,
0xaa, 0x4, 0x11, 0x46, 0x6b, 0x2d, 0x48, 0xa1
开发者_如何学C };
private static readonly byte[] IV = {
0x6d, 0x2d, 0xf5, 0x34, 0xc7, 0x60, 0xc5, 0x33,
0xe2, 0xa3, 0xd7, 0xc3, 0xf3, 0x39, 0xf2, 0x16
};
These are just declarations and initializations of byte array variables, filling them with the appropriate data. So Key
will be a byte array whose first element is 0xda, etc.
The variables are read-only, but that doesn't mean they're immutable - code could still modify the data within the array; the variables being read-only just means that they can't be made to refer to different arrays.
There's no output as such - the snippet of code you've provided just sets two variables.
These are buffers used by DES encryption; the first is the key and the second the vector. Here's a possible code for Encryption:
public static string Encrypt(string data)
{
MemoryStream output;
using (output = new MemoryStream())
{
byte[] byteData = new UnicodeEncoding().GetBytes(data);
TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();
using (CryptoStream cs = new CryptoStream(output, des.CreateEncryptor(Key, IV), CryptoStreamMode.Write))
{
cs.Write(byteData, 0, byteData.Length);
}
}
return Convert.ToBase64String(output.ToArray());
}
精彩评论