private static PgpSecretKey ReadSecretKey(Stream input) { PgpKeyRingBundle pgpSec = new PgpKeyRingBundle(PgpUtilities.GetDecoderStream(input)); // // we just loop through the collection till we find a key suitable for encryption, in the real // world you would probably want to be a bit smarter about this. // foreach (PgpSecretKeyRing keyRing in pgpSec.GetSecretKeyRings()) { foreach (PgpSecretKey key in keyRing.GetSecretKeys()) { if (key.IsSigningKey) { return(key); } } } throw new ArgumentException("Can't find signing key in key ring."); }
private List <PgpPrivateKey> GetAllPrivateKeys() { List <PgpPrivateKey> PgpPrivateKeys = new List <PgpPrivateKey>(); foreach (var keyInfo in this.PrivateKeys) { PgpKeyRingBundle pgpSec = new PgpKeyRingBundle(PgpUtilities.GetDecoderStream(keyInfo.PrivateKeyStream)); var keyRings = pgpSec.GetSecretKeyRings(); foreach (PgpSecretKeyRing keyRing in keyRings) { var pgpSecKeys = keyRing.GetSecretKeys(); foreach (PgpSecretKey pgpSecKey in pgpSecKeys) { var privateKey = pgpSecKey.ExtractPrivateKey(keyInfo.PrivateKeyPassword == null ? null : keyInfo.PrivateKeyPassword.ToCharArray()); PgpPrivateKeys.Add(privateKey); } } } return(PgpPrivateKeys); }