Example #1
0
        private void DoTestKey(BigInteger keyId, string passphrase, bool utf8)
        {
            PgpSecretKeyRingBundle secretKeyRing = LoadSecretKeyCollection("secring.gpg");

            PgpSecretKeyRing secretKey = secretKeyRing.GetSecretKeyRing(keyId.LongValue);

            Assert.NotNull(secretKey, "Could not locate secret keyring with Id=" + keyId.ToString(16));

            PgpSecretKey key = secretKey.GetSecretKey();

            Assert.NotNull(key, "Could not locate secret key!");

            try
            {
                char[] pass = passphrase.ToCharArray();

                PgpPrivateKey privateKey = utf8
                    ?   key.ExtractPrivateKeyUtf8(pass)
                    :   key.ExtractPrivateKey(pass);

                Assert.IsTrue(privateKey.KeyId == keyId.LongValue);
            }
            catch (PgpException e)
            {
                throw new PgpException("Password incorrect!", e);
            }

            // all fine!
        }