Esempio n. 1
0
        /// <summary>
        /// Replace the public key set on the secret ring with the corresponding key off the public ring.
        /// </summary>
        /// <param name="secretRing">Secret ring to be changed.</param>
        /// <param name="publicRing">Public ring containing the new public key set.</param>
        public static PgpSecretKeyRing ReplacePublicKeys(
            PgpSecretKeyRing secretRing,
            PgpPublicKeyRing publicRing)
        {
            IList newList = Platform.CreateArrayList(secretRing.keys.Count);

            foreach (PgpSecretKey sk in secretRing.keys)
            {
                PgpPublicKey pk = publicRing.GetPublicKey(sk.KeyId);

                newList.Add(PgpSecretKey.ReplacePublicKey(sk, pk));
            }

            return(new PgpSecretKeyRing(newList));
        }
Esempio n. 2
0
        public void TestMethod1()
        {
            string secretKeyFile = @"-----BEGIN PGP PRIVATE KEY BLOCK-----
Version: BCPG C# v1.7.4137.9688

lQc0BFTbeXUBEACgRx6VZYo0M8Vhv7D+ukhEPAIQHmbv41oae3vCINyEk+qdlkRQ
qa+prxLyM3wvHi2WyUQUG67TgEhOKGiu5iRT3SDf7/o2+GyzkcJxVf4SsauvPNM9
chRtayHhtgNbkz+qS3G+zGgO52ck/W9J4EvxzeMaV+hN9TJm4nurZ52ZxqjxXDX2
9/loc639n/OCQTx3BKNPwt8TE3vaHUi7QScfL3Yj/zL3FDR8ct2Ymh4xWM2GjTb6
3mPWAt0pOfFOS0wxWpWYg9gl3p6iw8Sl7O5cqlxNlpA3b1b4mdF1v96kNfxkT4MI
lNhfeNQ6e9cUZbMSJxt/gzY29xERa7kYpVC5QOgI57VZg/hsO8Uoh55H7LgKQ8Zw
y4IQ/BZxBvMgBMVjYOHyhfC1rx81btPZbMHN6rwQFlXgXc+pbKTSzxmsCh00lc9z
Ib653ByqHLeF4H++T6aU7L15C+8xOuFctF1wYLGjnr6ZX5tZINuyOqq2ifQ0wkkk
xu7Ev/AIhE9oOYmn8HfwbUZOb28FbSqYssxzI76QTaPzOULJ+q/M94Z6WCTyXxHV
uTFbhhlOn6FMK4AbUAseLO34w8rxYuwL50XdUlapW6yCxbtJIL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rO03TJJ2ZQ
/zw8KKfzGzE89hO7z7cX+0UNODY++AbS21+0Cc7eN/DAehe0bjedYg8PPJ/xJ7uL
A+GoSqVuY2ilY2E3A5fw+x57Of8FibUlCx1lyYFaAyQ87kivNSsD9S/PyZ2q516h
GIrQTgk34Pda4qZ/PtWGcJoT6mwHTz85HqBp0NO4/NvJG+ySw5kqVaR0W8yJ7Jat
mqcuSIOyrw9X69uzoIzMNv2vmzN3F3czg5VGRcQVcDU0GVhq8VFUBBhQLUGiNFJM
QO8KIwcFabhhu5ymAGTnyBBfetDr+0pqOLol0WKDFz4IF9DeLnESRqcl00Evx7/o
viUOB7IZCHwFa3yRoyM8ZC2/p3phK8dreV2xPaPyyNbkl0768Spoa7s+59D9MoXC
TP0+SvCeBf8jJpJ6/O/xUAvyPRvyk75+H6kOu0+4G7erK0AABb1WQvmYah1wPzD3
1ptfooPAKf193dtiOC2AoJdGu/oFmffgh0WhcbPCKlHv0zecx0DTGDkAQWAe9L+i
BQ7R6w==
=Z4JC
-----END PGP PRIVATE KEY BLOCK-----";

            File.WriteAllText(Path.Combine(@"C:\Users\John\BcPGP", "testuser1@example_com_secret.asc"), secretKeyFile);
            MemoryStream     msSec   = new MemoryStream(Encoding.UTF8.GetBytes(secretKeyFile));
            PgpSecretKeyRing secRing = new PgpSecretKeyRing(PgpUtilities.GetDecoderStream(msSec));

            char[]           passPhrase = new char[] { 't', 'e', 's', 't', 'u', 's', 'e', 'r' };
            PgpPublicKeyRing pubRing    = new PgpPublicKeyRing(secRing.GetPublicKey().GetEncoded());

            PgpPublicKeyRing newRing = new PgpPublicKeyRing(
                new MemoryStream(RevokePublicKey(secRing.GetSecretKey(), passPhrase, pubRing.GetPublicKey(), true)));

            msSec.Close();
            Assert.IsTrue(newRing.GetPublicKey().IsRevoked());

            Stream fos = File.Create(@"C:\Users\John\BcPGP\RevokedKey.asc");
            ArmoredOutputStream aOut = new ArmoredOutputStream(fos);

            newRing.Encode(aOut);
            aOut.Close();
            fos.Close();

            PgpSecretKey        newSecret = PgpSecretKey.ReplacePublicKey(secRing.GetSecretKey(), newRing.GetPublicKey());
            Stream              foSec     = File.Create(@"C:\Users\John\BcPGP\SecretRevokedKey.asc");
            ArmoredOutputStream sOut      = new ArmoredOutputStream(foSec);

            newSecret.Encode(sOut);
            sOut.Close();
            foSec.Close();
            Assert.IsTrue(newSecret.PublicKey.IsRevoked());
        }