public static IEnumerable <PgpPublicKeyMetaData> GetPublicKeys(Stream inputStream) //, bool disallowPrivateKeys)
        {
            inputStream = PgpUtilities.GetDecoderStream(inputStream);

            //if (disallowPrivateKeys)
            //{
            //    PgpSecretKeyRingBundle pgpKeyRing = null;
            //    try
            //    {
            //        pgpKeyRing = new PgpSecretKeyRingBundle(inputStream);
            //    }
            //    catch
            //    {
            //    }
            //    if (pgpKeyRing != null && pgpKeyRing.Count > 0)
            //    {
            //        throw new System.Security.SecurityException("Private keys are not allowed.");
            //    }
            //}

            var list = new List <PgpPublicKeyMetaData>();

            PgpPublicKeyRingBundle pgpPub = new PgpPublicKeyRingBundle(inputStream);

            foreach (PgpPublicKeyRing keyRing in pgpPub.GetKeyRings())
            {
                foreach (PgpPublicKey key in keyRing.GetPublicKeys())
                {
                    var keyMeta = new PgpPublicKeyMetaData();
                    keyMeta.Load(key);
                    list.Add(keyMeta);
                }
            }
            return(list);
        }
        private static bool ValidateBitStrength(PgpPublicKeyMetaData key, List <string> errors)
        {
            // key strength
            bool validStregth = false;

            if (key.BitStrength == 2048 || key.BitStrength == 4096)
            {
                validStregth = true;
            }
            if (!validStregth)
            {
                errors.Add(string.Format("Key '{0}' requires either 2048 or 4096 bit strength.", key.KeyIdShort));
                return(false);
            }
            if (key.SubKeys != null && key.SubKeys.Any())
            {
                foreach (var subKey in key.SubKeys)
                {
                    var isValid = ValidateBitStrength(subKey, errors);
                    if (!isValid)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
 private static bool ValidateVersion(PgpPublicKeyMetaData key, List <string> errors)
 {
     // key strength
     if (key.Version < 3)
     {
         errors.Add(string.Format("Key '{0}' must be >= version 3.", key.KeyIdShort));
         return(false);
     }
     if (key.SubKeys != null && key.SubKeys.Any())
     {
         foreach (var subKey in key.SubKeys)
         {
             var isValid = ValidateVersion(subKey, errors);
             if (!isValid)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
        public static IEnumerable<PgpPublicKeyMetaData> GetPublicKeys(Stream inputStream) //, bool disallowPrivateKeys)
        {

            inputStream = PgpUtilities.GetDecoderStream(inputStream);

            //if (disallowPrivateKeys)
            //{
            //    PgpSecretKeyRingBundle pgpKeyRing = null;
            //    try
            //    {
            //        pgpKeyRing = new PgpSecretKeyRingBundle(inputStream);
            //    }
            //    catch
            //    {
            //    }
            //    if (pgpKeyRing != null && pgpKeyRing.Count > 0)
            //    {
            //        throw new System.Security.SecurityException("Private keys are not allowed.");
            //    }
            //}

            var list = new List<PgpPublicKeyMetaData>();

            PgpPublicKeyRingBundle pgpPub = new PgpPublicKeyRingBundle(inputStream);

            foreach (PgpPublicKeyRing keyRing in pgpPub.GetKeyRings())
            {
                foreach (PgpPublicKey key in keyRing.GetPublicKeys())
                {
                    var keyMeta = new PgpPublicKeyMetaData();
                    keyMeta.Load(key);
                    list.Add(keyMeta);
                }
            }
            return list;
        }
 private static bool ValidateVersion(PgpPublicKeyMetaData key, List<string> errors)
 {
     // key strength
     if (key.Version < 3)
     {
         errors.Add(string.Format("Key '{0}' must be >= version 3.", key.KeyIdShort));
         return false;
     }
     if (key.SubKeys != null && key.SubKeys.Any())
     {
         foreach (var subKey in key.SubKeys)
         {
             var isValid = ValidateVersion(subKey, errors);
             if (!isValid)
             {
                 return false;
             }
         }
     }
     return true;
 }
 private static bool ValidateBitStrength(PgpPublicKeyMetaData key, List<string> errors)
 {
     // key strength
     bool validStregth = false;
     if (key.BitStrength == 2048 || key.BitStrength == 4096)
     {
         validStregth = true;
     }
     if (!validStregth)
     {
         errors.Add(string.Format("Key '{0}' requires either 2048 or 4096 bit strength.", key.KeyIdShort));
         return false;
     }
     if (key.SubKeys != null && key.SubKeys.Any())
     {
         foreach (var subKey in key.SubKeys)
         {
             var isValid = ValidateBitStrength(subKey, errors);
             if (!isValid)
             {
                 return false;
             }
         }
     }
     return true;
 }