public static void TestStuff() { //Console.WriteLine("Testing key generation."); Pgp.KeyPair kpa = Pgp.GenerateKey(); //Console.WriteLine($"PublicKey:\n{kpa.publicKey}"); //Console.WriteLine($"PrivateKey:\n{kpa.privateKey}"); Pgp.KeyPair kpb = Pgp.GenerateKey(); string secret = "Oh yeet uhm yeeet 千ㄩ㇄㇄山工ᗪㄒ廾"; //Console.WriteLine($"Testing encryption: \"{secret}\""); string encrypted = Pgp.Encrypt(secret, kpa); //Console.WriteLine($"Encrypted as:\n{encrypted}"); string signed = Pgp.Sign(secret, kpa); //Console.WriteLine($"Signed as:\n{signed}"); string decrypted = Pgp.Decrypt(encrypted, kpa); //Console.WriteLine($"Decrpyted message: {decrypted}"); if (decrypted != secret) { throw new Exception("Pgp_Tests: Encryption/Decryption failed"); } if (!Pgp.Verify(signed, kpa)) { throw new Exception("Pgp_Tests: Sign/Verify failed"); } //Console.WriteLine($"Verify signed message: {Pgp.Verify(signed, kpa)}"); string encryptedAndSigned = Pgp.EncryptAndSign(secret, kpa.publicKey, kpb.privateKey); //Console.WriteLine($"Asymetrically encrypted and signed:\n{encryptedAndSigned}"); string decryptedAndVerified; if (Pgp.DecryptAndVerify(encryptedAndSigned, kpb.publicKey, kpa.privateKey, out decryptedAndVerified)) { //Console.WriteLine($"Decrypted and verified message: {decryptedAndVerified}"); } else { throw new Exception("Pgp_Tests: DecryptAndVerify failed!"); } string cannedString = @"-----BEGIN PGP MESSAGE----- Version: BCPG C# v1.8.8.0 hIwD6x2om9L5x94BA/4qH6xwB5Z09I85LpqmKVQJHozs5mYxWIpT9FMy207Kbnk/ aULhR52dX7GCPLqZkaz2QzzRrJOzSB9C/g2cAvB6eq6Q7+dr22AsFZkDhzg0s04j 7njj1fxKYO/nBUcE+w9jqEXm/C/3tkY44GnmSYPeBnL2HdoqtSeAnZjLI3924NLA XQGSluiRItEIrNNa3DU0Bn5i+zYQZZCcCqWr2HnCruS8/D/jwwNo/UixoL36GfiZ MzOK14+a98Wuoniiq3OKcAVMON7ivuEaYhsoTq+P8jLhfS1hmN32gaA4nbdXG/wu n2ZmnibWYS8ezkrrztsAZubrIRjO9dtqnX1sWI+gLr2j75jageV2K1QNZrxaST2b WMX92WZJ6uaq8MZ58ljbzo1IJrONw0ljINp90h8fXk/KfTfJiZcGLtSFshX2cjkR JjTJ5lyWXsXaNW+3LVOb1J1ZNkKYUvDzDT14S5C/bxPQ52CxnBi/2t+EREKZGVW/ /2htRaAL65hqcgleOIfCU0oN5UbTk6kdppr7vC9yMqDGpc2j7KI6FX0INeNrCg== =hlqF -----END PGP MESSAGE-----"; if (Pgp.DecryptAndVerify(cannedString, kpb.publicKey, kpa.privateKey, out decryptedAndVerified)) { throw new Exception("Pgp_Tests: DecryptAndVerify succeeded on bad data! Not good - either you won the lottery or there's a bug!"); } else { //Console.WriteLine("DecryptAndVerify failed successfully on mutated data!"); } }
/// <summary> Default function to decrypt sensitive information with </summary> public string DefaultDecrypt(string encoded) { return(Pgp.Decrypt(encoded, kp)); }