I Have a hash that I've created from a PDF file with the function below:
using System.Security.Cryptography;
private readonly SHA256 fileToSha256 = SHA256.Create();
public string FileToBase64SHA256(string fileName)
{
using(FileStream stream = File.OpenRead(fileName))
{
byte[] streamToSHA = fileToSha256.ComputeHash(stream);
return Convert.ToBase64String(streamToSHA);
}
}
How could I Decrypt the result hash above and save it in a PDF file again? I am trying something like this, but the file saved is corrupted, with strange characters:
public string HashToFile(string hashedFile, string fileName)
{
BinaryWriter Writer = null;
byte[] data;
try
{
Writer = new BinaryWriter(File.OpenWrite(fileName));
data = Convert.FromBase64String(hashedFile);
Writer.Write(data);
Writer.Flush();
Writer.Close();
return "Saved Successfully";
}
catch
{
return "Error converting to File";
}
}