static void Main(string[] args) { var publicKey = new EncryptionKeys(File.ReadAllText(Path.Combine(ROOT_KEYS, PUBLIC_KEY))); var privateKey = new EncryptionKeys(File.ReadAllText(Path.Combine(ROOT_KEYS, PRIVATE_KEY)), "Password1!"); using (var publicPgp = new PGP(publicKey)) using (var privatePgp = new PGP(privateKey)) { privatePgp.ClearSignFile( Path.Combine(ROOT, UNENCRYPTED_FILE), Path.Combine(ROOT, SIGNED_FILE)); publicPgp.EncryptFile( Path.Combine(ROOT, SIGNED_FILE), Path.Combine(ROOT, ENCRYPTED_FILE)); // Likely would want to use EncryptFileAndSign instead of two passes privatePgp.DecryptFile( Path.Combine(ROOT, ENCRYPTED_FILE), Path.Combine(ROOT, DECRYPTED_FILE)); Console.WriteLine("It was me who signed the file: {0}", publicPgp.VerifyClearFile(Path.Combine(ROOT, DECRYPTED_FILE))); } using (var pgp = new PGP(new EncryptionKeys(File.ReadAllText(Path.Combine(ROOT_KEYS, RANDOM_PUBLIC_KEY))))) { Console.WriteLine("It was me who signed the file: {0}", pgp.VerifyClearFile(Path.Combine(ROOT, DECRYPTED_FILE))); } }
public void ClearSignAndVerifyFile_CreateClearSignedFileAndVerify(KeyType keyType) { // Arrange TestFactory testFactory = new TestFactory(); testFactory.Arrange(keyType, FileType.Known); PGP pgp = new PGP(); // Act pgp.ClearSignFile(testFactory.ContentFilePath, testFactory.SignedContentFilePath, testFactory.PrivateKeyFilePath, testFactory.Password); // Assert Assert.True(pgp.VerifyClearFile(testFactory.SignedContentFilePath, testFactory.PublicKeyFilePath)); // Teardown testFactory.Teardown(); }