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.PGPAssembly: Walter.Cypher (in Walter.Cypher.dll)
Syntax
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 successfulExamples
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");