DES加密解密的问题
1)我下载了一个DES加密解密的可执行文件,输入要求是16个字符,如 "1A1A111111111111 ",密钥也是16个字符,而且字符是在0-9、A-F的范围之内。并且每两个字符被认为是一个数字。请问:如果AB代表的数字是什么?如何换算?
2)我在网上看到一段c#的代码,密钥都要求是8个字符的,但加密出来的结果是一些比较奇怪的字符。如123用12345678加密后的结果是A1+4PWKL=AcQy这样的形式的,怎么样才能让它输出为字符是在0-9、A-F的范围之内?并且密钥也改成输入为16个字符,程序把这16个字符转换成8位?
附:C#代码
//加密
public static string Encode(string data, string KEY_64, string IV_64)
{
byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_64);
byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_64);
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
int i = cryptoProvider.KeySize;
MemoryStream ms = new MemoryStream();
CryptoStream cst = new CryptoStream(ms,cryptoProvider.CreateEncryptor(byKey,byIV),CryptoStreamMode.Write);
StreamWriter sw = new StreamWriter(cst);
sw.Write(data);
sw.Flush();
cst.FlushFinalBlock();
sw.Flush();
return Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length);
}
//解密
public static string Decode(string data)
{
byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_64);
byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_64);
byte[] byEnc;
try
{
byEnc = Convert.FromBase64String(data);
}
catch
{
return null;
}
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
MemoryStream ms = new MemoryStream(byEnc);
CryptoStream cst = new CryptoStream(ms,cryptoProvider.CreateDecryptor(byKey,byIV),CryptoStreamMode.Read);
StreamReader sr = new StreamReader(cst);