1、加密文件路径
string plan = Server.MapPath("") + "\\images\\Desert.jpg";
将文件转换成byte数据并加密为base64字符串
string aaa= System.Convert.ToBase64String(GetPictureData(plan));
字节转化函数与
public byte[] GetPictureData(string imagepath)
{
/**/
根据图片文件的路径使用文件流打开,并保存为byte[]
FileStream fs = new FileStream(imagepath, FileMode.Open);//可以是其他重载方法
byte[] byData = new byte[fs.Length];
fs.Read(byData, 0, byData.Length);
fs.Close();
return byData;
}
2、将图片文件解密为可保存的文件
将加密的base64文件字符串解密为byte数组
ReturnPhoto(System.Convert.FromBase64String(aaa)).Save(plan1);
将byte数组转化为图片文件函数
public System.Drawing.Image ReturnPhoto(byte[] streamByte)
{
System.IO.MemoryStream ms = new System.IO.MemoryStream(streamByte);
System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
return img;
}