예제 #1
0
        private List <PgpSignatureSubpacketVector> GetSignatureSubpacketVectors(PgpPublicKey key)
        {
            List <PgpSignatureSubpacketVector> result = new List <PgpSignatureSubpacketVector>();

            if (key.IsMasterKey)
            {
                foreach (int certificationType in certificationTypes)
                {
                    foreach (PgpSignature sig in key.GetSignaturesOfType(certificationType))
                    {
                        if (sig.HasSubpackets)
                        {
                            result.Add(sig.GetHashedSubPackets());
                        }
                    }
                }
            }
            else
            {
                foreach (PgpSignature sig in key.GetSignaturesOfType(PgpSignature.SubkeyBinding))
                {
                    if (sig.HasSubpackets)
                    {
                        result.Add(sig.GetHashedSubPackets());
                    }
                }
            }
            return(result);
        }
예제 #2
0
        public static void Main(
            string[] args)
        {
            if (args.Length == 1)
            {
                Stream fis = File.OpenRead(args[0]);

                PgpPublicKeyRing ring = new PgpPublicKeyRing(
                    PgpUtilities.GetDecoderStream(fis));
                PgpPublicKey key = ring.GetPublicKey();

                // iterate through all direct key signautures and look for NotationData subpackets
                foreach (PgpSignature sig in key.GetSignaturesOfType(PgpSignature.DirectKey))
                {
                    Console.WriteLine("Signature date is: "
                                      + sig.GetHashedSubPackets().GetSignatureCreationTime());

                    NotationData[] data = sig.GetHashedSubPackets().GetNotationDataOccurrences();

                    for (int i = 0; i < data.Length; i++)
                    {
                        Console.WriteLine("Found Notation named '" + data[i].GetNotationName()
                                          + "' with content '" + data[i].GetNotationValue() + "'.");
                    }
                }

                fis.Close();
            }
            else if (args.Length == 5)
            {
                Stream secFis = File.OpenRead(args[0]);
                Stream pubFis = File.OpenRead(args[2]);

                // gather command line arguments
                PgpSecretKeyRing secRing = new PgpSecretKeyRing(
                    PgpUtilities.GetDecoderStream(secFis));
                String           secretKeyPass = args[1];
                PgpPublicKeyRing ring          = new PgpPublicKeyRing(
                    PgpUtilities.GetDecoderStream(pubFis));
                String notationName  = args[3];
                String notationValue = args[4];

                // create the signed keyRing
                PgpPublicKeyRing sRing = null;
                sRing = new PgpPublicKeyRing(
                    new MemoryStream(
                        SignPublicKey(secRing.GetSecretKey(), secretKeyPass,
                                      ring.GetPublicKey(), notationName, notationValue, true),
                        false));
                ring = sRing;

                secFis.Close();
                pubFis.Close();

                Stream fos = File.Create("SignedKey.asc");

                // write the created keyRing to file
                ArmoredOutputStream aOut = new ArmoredOutputStream(fos);
                sRing.Encode(aOut);
                aOut.Close();

                // Note: ArmoredOutputStream.Close() leaves underlying stream open
                fos.Close();
            }
            else
            {
                Console.Error.WriteLine("usage: DirectKeySignature secretKeyFile secretKeyPass publicKeyFile(key to be signed) NotationName NotationValue");
                Console.Error.WriteLine("or: DirectKeySignature signedPublicKeyFile");
            }
        }