Exemple #1
0
 static void p5_crypto_list_private_keys(ApplicationContext context, ActiveEventArgs e)
 {
     // Using common helper to iterate all secret keys.
     ObjectIterator.MatchingPrivateKeys(context, e.Args, delegate(PgpSecretKey key) {
         // Retrieving fingerprint of currently iterated key, and returning to caller.
         var fingerprint = BitConverter.ToString(key.PublicKey.GetFingerprint()).Replace("-", "").ToLower();
         e.Args.Add(fingerprint);
     }, false);
 }
Exemple #2
0
        static void p5_crypto_get_private_key(ApplicationContext context, ActiveEventArgs e)
        {
            // Using common helper to iterate all secret keys.
            ObjectIterator.MatchingPrivateKeys(context, e.Args, delegate(PgpSecretKey key) {
                // Retrieving fingerprint of currently iterated key, and returning to caller.
                var fingerprint = BitConverter.ToString(key.PublicKey.GetFingerprint()).Replace("-", "").ToLower();
                var node        = e.Args.Add(fingerprint).LastChild;

                // This is the key we're looking for
                using (var memStream = new MemoryStream()) {
                    using (var armored = new ArmoredOutputStream(memStream)) {
                        key.Encode(armored);
                        armored.Flush();
                    }
                    memStream.Flush();
                    memStream.Position = 0;
                    var sr             = new StreamReader(memStream);
                    node.Value         = sr.ReadToEnd();
                }
            }, false);
        }