S
Stephanie Yao via .NET 247
Hi, I've got some problem on encryption and decryption,here is my code:
public string Encrypt(string eptData)
{
MemoryStream ms = new MemoryStream();
transformer.IV = initVec;
transformer.Key = encKey;
ICryptoTransform transform = transformer.GetCryptoServiceProvider();
CryptoStream encStream = new CryptoStream(ms,
transform,
CryptoStreamMode.Write);
//??here is the problem, the rest code are not performed, it said System.FormatException:Base-64 char array invalid length
try
{
byte[] eptBytes = Convert.FromBase64String(eptData);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
try
{
encStream.Write(eptBytes, 0, eptBytes.Length);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
encStream.FlushFinalBlock();
try
{
encStream.Close();
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
string eptResult = Convert.ToBase64String(ms.ToArray());
return eptResult;
}
anyone can help me?
public string Encrypt(string eptData)
{
MemoryStream ms = new MemoryStream();
transformer.IV = initVec;
transformer.Key = encKey;
ICryptoTransform transform = transformer.GetCryptoServiceProvider();
CryptoStream encStream = new CryptoStream(ms,
transform,
CryptoStreamMode.Write);
//??here is the problem, the rest code are not performed, it said System.FormatException:Base-64 char array invalid length
try
{
byte[] eptBytes = Convert.FromBase64String(eptData);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
try
{
encStream.Write(eptBytes, 0, eptBytes.Length);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
encStream.FlushFinalBlock();
try
{
encStream.Close();
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
string eptResult = Convert.ToBase64String(ms.ToArray());
return eptResult;
}
anyone can help me?