WALTER | Workable Algorithms for Location-aware Transmission, Encryption Response

PGPManaged..::..TryDecrypt Method (String, String, String%)

Try and decrypt the specified encrypted text using the provided private key, Return false if fails

Namespace:  Walter.Cypher.PGP
Assembly:  Walter.Cypher (in Walter.Cypher.dll)

Syntax


public bool TryDecrypt(
	string encryptedText,
	string privateKey,
	out string cleartext
)

Parameters

encryptedText
Type: String
The encrypted text.
privateKey
Type: String
The private key.
cleartext
Type: String%
the decrypted text or string.Empty if failed

Return Value

True if decipher was successful

Examples


C#
var keyGen = new PGPKeyGenerator();

   var keyRing = keyGen.GenerateKeys(PGPKeySize.Key2048);
   var wrongKey = keyGen.GenerateKeys(PGPKeySize.Key2048);
   var pgp = new PGPManaged();
   var smallTextFile = "ABC";
   var secure = pgp.Encrypt(smallTextFile, keyRing.PublicKey);

   if (pgp.TryDecrypt(secure, wrongKey.PrivateKey, out var copy) || pgp.TryDecrypt(secure, keyRing.PrivateKey, out copy))
      Assert.AreEqual(smallTextFile, copy);
   else
      Assert.Inconclusive("Decipher failed");