无论如何将字节数组转换为图像并将其直接显示在图像控件中而不将其保存在磁盘上?
这是我到目前为止开发的代码:
protected void btnShow_Click(object sender, System.EventArgs e)
{
Byte[] blobEncryptedImage = Signature.Get(txSaleGUID.Text);
Crypto crypto = new Crypto("mypass");
Byte[] decryptedImage = Encoding.ASCII.GetBytes(crypto.Decrypt(blobEncryptedImage));
MemoryStream ms = new MemoryStream(decryptedImage);
Image img = Image.FromStream(ms);
//Image1.ImageUrl = System.Drawing.Image.FromStream(ms);
}
public static Image byteArrayToImage(byte[] data)
{
using (System.IO.MemoryStream ms = new System.IO.MemoryStream(data))
{
return new System.Drawing.Bitmap(Image.FromStream(ms));
}
}
更新 1
这是我的加密课程:
public class Crypto
{
private ICryptoTransform rijndaelDecryptor;
// Replace me with a 16-byte key, share between Java and C#
private static byte[] rawSecretKey = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
public Crypto(string passphrase)
{
byte[] passwordKey = encodeDigest(passphrase);
RijndaelManaged rijndael = new RijndaelManaged();
rijndaelDecryptor = rijndael.CreateDecryptor(passwordKey, rawSecretKey);
}
public string Decrypt(byte[] encryptedData)
{
byte[] newClearData = rijndaelDecryptor.TransformFinalBlock(encryptedData, 0, encryptedData.Length);
return Encoding.ASCII.GetString(newClearData);
}
public string DecryptFromBase64(string encryptedBase64)
{
return Decrypt(Convert.FromBase64String(encryptedBase64));
}
private byte[] encodeDigest(string text)
{
MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] data = Encoding.ASCII.GetBytes(text);
return x.ComputeHash(data);
}
}
任何人都可以提供线索吗?