Created
January 5, 2020 07:44
-
-
Save SumindaD/55e4189cbabdbcfd3d573790b833b15e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
namespace SignImages | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
const string PrivateKeryCertName = "PrivateKeyCert.pfx"; | |
const string PrivateKeryCertPassword = "1234"; | |
const string ImageFilePath = "Image.png"; | |
const string SignedXMLDocumentPath = "SignedXML.xml"; | |
const string RecreatedImagePath = "RecreatedImage.png"; | |
if (!File.Exists(PrivateKeryCertName)) | |
Console.WriteLine(PrivateKeryCertName + " file does not exists!"); | |
else if (!File.Exists(ImageFilePath)) | |
Console.WriteLine(ImageFilePath + " file does not exists!"); | |
else | |
{ | |
if (!File.Exists(SignedXMLDocumentPath)) | |
{ | |
Console.WriteLine("Signing the Image"); | |
ImageCryptographyManager.SignImage(File.ReadAllBytes(ImageFilePath), File.ReadAllBytes(PrivateKeryCertName), PrivateKeryCertPassword, SignedXMLDocumentPath); | |
Console.WriteLine("Image signed as XML"); | |
} | |
else | |
{ | |
var integrityCheckPassed = ImageCryptographyManager.VerifyImage(SignedXMLDocumentPath, File.ReadAllBytes(PrivateKeryCertName), PrivateKeryCertPassword); | |
if (integrityCheckPassed) | |
{ | |
Console.WriteLine("Image integrity Intact!"); | |
var imageBuffer = ImageCryptographyManager.GetImage(SignedXMLDocumentPath); | |
File.WriteAllBytes(RecreatedImagePath, imageBuffer); | |
Console.WriteLine("Image Unsigned and re-created!"); | |
} | |
else | |
Console.WriteLine("Image has been tampered with!"); | |
} | |
} | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment