private static void PhotoAbnormalCodeCheck()
{
var ZhaoPian = "";//照片base64字符串
MemoryStream ms = new MemoryStream(Convert.FromBase64String(ZhaoPian));
byte[] content1 = new byte[ms.Length];
for (int i = 0; i < content1.Length; i++)
{
content1[i] = (byte)ms.ReadByte();
}
var fileString = Encoding.Default.GetString(content1);
Console.WriteLine(fileString);
if (fileString.Contains("<script") || fileString.Contains("<Script") || fileString.Contains("<SCRIPT") || fileString.Contains("body") || fileString.Contains("<!DOCTYPE")
|| fileString.Contains("<html") || fileString.Contains("<head>") || fileString.Contains("<div") || fileString.Contains("</html>"))
{
ms.Close();
Console.WriteLine("一寸照片中包含异常编码,存在安全隐患,请更换照片上传");
return;
}
ms.Close();
}