PDA

View Full Version : اخطار Invalid length for a Base-64 char array



reza11_2005
جمعه 20 بهمن 1396, 08:44 صبح
با سلام من برای رمزنگاری و باز کردن آن از تابع زیر استفاده می کنم اما به مشکل برخوردام

public static string InsertAndUpdate(string strValue, string Value)
{

byte[] byKey;
byte[] IV = { 18, 52, 86, 120, 144, 171, 205, 239 };
try
{
byKey = System.Text.Encoding.UTF8.GetBytes(Value.Substring (0, 8));
System.Security.Cryptography.DESCryptoServiceProvi der des = new System.Security.Cryptography.DESCryptoServiceProvi der();
byte[] inputByteArray = System.Text.Encoding.UTF8.GetBytes(strValue);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
System.Security.Cryptography.CryptoStream cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateEncryptor(byKey, IV), System.Security.Cryptography.CryptoStreamMode.Writ e);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
catch (Exception E)
{
throw E;
}

}

public static string SelectInfo(string strValue, string Value)
{
byte[] byKey;
byte[] IV = { 18, 52, 86, 120, 144, 171, 205, 239 };
byte[] inputByteArray;
//inputByteArray.Length = strText.Length;
try
{
byKey = System.Text.Encoding.UTF8.GetBytes(Value.Substring (0, 8));
System.Security.Cryptography.DESCryptoServiceProvi der des = new System.Security.Cryptography.DESCryptoServiceProvi der();
inputByteArray = Convert.FromBase64String(strValue);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
System.Security.Cryptography.CryptoStream cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateDecryptor(byKey, IV), System.Security.Cryptography.CryptoStreamMode.Writ e);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
System.Text.Encoding encoding = System.Text.Encoding.UTF8;
return encoding.GetString(ms.ToArray());
}
catch (Exception E)
{

throw E;
}

}

reza11_2005
جمعه 20 بهمن 1396, 08:45 صبح
البته در بازنگری رمز هش شده منظورم SelectInfo است