예제 #1
0
        public void TestVerifyFailInvalidSignature()
        {
            Gpg g = new Gpg(GPG_BINARY_PATH);

            g.Passphrase = GPG_PASSWORD;

            byte[]       data = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04 };
            MemoryStream tbs  = new MemoryStream(data);
            MemoryStream sig  = new MemoryStream();

            g.Sign(tbs, sig);

            Assert.IsTrue(sig.Length > 0);

            // tweak a few bytes on the sig to invalidate it
            sig.Position = sig.Length / 2 - 1;
            sig.WriteByte(0xFF);
            sig.WriteByte(0xFF);
            sig.WriteByte(0xFF);

            // set the postion in the signature stream to start reading from at the beginning
            sig.Position = 0;

            Assert.Throws <GpgException>(() => g.Verify(sig));
        }
예제 #2
0
        static void Main(string[] args)
        {
            string keyId  = "416AB815";
            string passwd = "abc123!";

            byte[]       byteArray = Encoding.ASCII.GetBytes("Some text");
            MemoryStream input     = new MemoryStream(byteArray);
            MemoryStream output    = new MemoryStream();
            Gpg          gpg       = new Gpg("C:\\Program Files (x86)\\GNU\\GnuPG\\pub\\gpg.exe");

            gpg.OutputType          = OutputTypes.AsciiArmor;
            gpg.Passphrase          = passwd;
            gpg.LocalUser           = keyId;
            gpg.OutputSignatureType = OutputSignatureTypes.ClearText;
            gpg.Sign(input, output);
            output.Position = 0;
            StreamReader reader      = new StreamReader(output);
            string       text        = reader.ReadToEnd();
            MemoryStream outputVer   = new MemoryStream();
            var          verifiedKey = gpg.Verify(output, outputVer);

            outputVer.Position = 0;
            StreamReader reader2 = new StreamReader(outputVer);
            string       text2   = reader2.ReadToEnd();

            Console.WriteLine("Found key " + verifiedKey);
            Console.WriteLine("Output: " + text2);
            Console.ReadKey();
        }
예제 #3
0
        public void TestSign(OutputSignatureTypes sigType)
        {
            Gpg g = new Gpg(GPG_BINARY_PATH);

            g.LocalUser           = GPG_LOCAL_USER_KEY;
            g.Passphrase          = GPG_PASSWORD;
            g.OutputSignatureType = sigType;

            byte[]       data = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04 };
            MemoryStream tbs  = new MemoryStream(data);
            MemoryStream sig  = new MemoryStream();

            g.Sign(tbs, sig);

            Assert.IsTrue(sig.Length > 0);
        }
예제 #4
0
        public void TestSignVerify()
        {
            Gpg g = new Gpg(GPG_BINARY_PATH);

            g.LocalUser  = GPG_LOCAL_USER_KEY;
            g.Passphrase = GPG_PASSWORD;

            byte[]       data = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04 };
            MemoryStream tbs  = new MemoryStream(data);
            MemoryStream sig  = new MemoryStream();

            g.Sign(tbs, sig);

            Assert.IsTrue(sig.Length > 0);

            // set the postion in the signature stream to start reading from at the beginning
            sig.Position = 0;

            g.Verify(sig);
        }