예제 #1
0
        public void TestBinaryWatermark()
        {
            BinaryWatermark mark = new BinaryWatermark(new byte[] { 1, 2, 3, 4 });

            Watermarker.EmbedWatermark(file, mark, "password", "results/BinaryMark.png");

            PNGFile file2 = new PNGFile("results/BinaryMark.png");

            BinaryWatermark extract = (BinaryWatermark)Watermarker.ExtractWatermark(file2, "password");

            Expect(extract.data, Is.EqualTo(new byte[] { 1, 2, 3, 4 }));
        }
예제 #2
0
        public void TestTextWatermark()
        {
            TextWatermark mark = new TextWatermark("This is a test");

            Watermarker.EmbedWatermark(file, mark, "password", "results/TextMark.png");

            PNGFile file2 = new PNGFile("results/TextMark.png");

            TextWatermark extract = Watermarker.ExtractWatermark <TextWatermark>(file2, "password");

            Expect(extract.Text, Is.EqualTo("This is a test"));
        }
예제 #3
0
        public void TestFileWatermark()
        {
            FileWatermark mark = new FileWatermark(@"TestFile.txt");

            Watermarker.EmbedWatermark(file, mark, "password", "results/FileMark.png");


            PNGFile file2 = new PNGFile("results/FileMark.png");

            FileWatermark extract = (FileWatermark)Watermarker.ExtractWatermark(file2, "password");

            Expect(extract.extension, Is.EqualTo(".txt"));
            Expect(extract.fileData, Is.EqualTo(System.Text.Encoding.UTF8.GetBytes("This is a test file!")));
        }
예제 #4
0
        public void TestScrambling()
        {
            TextWatermark mark = new TextWatermark("This is a test");


            Watermarker.EmbedWatermark(file, mark, "password", "results/Scrambling.png");


            PNGFile file2 = new PNGFile("results/TextMark.png");

            TextWatermark extracted = Watermarker.ExtractWatermark <TextWatermark>(file2, "password");


            extracted = Watermarker.ExtractWatermark <TextWatermark>(file2, "foobar");

            Expect(extracted, Is.Null);
        }
예제 #5
0
        public void TestEncryptedWatermark()
        {
            EncryptedWatermark.Algorithm = aes;

            TextWatermark      mark      = new TextWatermark("This should be encrypted");
            EncryptedWatermark encrypted = new EncryptedWatermark(mark, "super-secret");

            Watermarker.EmbedWatermark(file, encrypted, "password", "results/EncryptedMark.png");


            PNGFile            file2   = new PNGFile("results/EncryptedMark.png");
            EncryptedWatermark extract = (EncryptedWatermark)Watermarker.ExtractWatermark(file2, "password");

            mark = extract.Decrypt <TextWatermark>("super-secret");

            Expect(mark, Is.Not.Null);

            Expect(mark.Text, Is.EqualTo("This should be encrypted"));
        }
예제 #6
0
        public void TestCompositeWatermark()
        {
            EncryptedWatermark.Algorithm = aes;

            CompositeWatermark comp  = new CompositeWatermark();
            TextWatermark      mark1 = new TextWatermark("This is mark #1");
            TextWatermark      mark2 = new TextWatermark("This is mark #2");

            EncryptedWatermark enc = new EncryptedWatermark(mark1, "supersecret");

            comp.AddWatermark(mark1);
            comp.AddWatermark(mark2);
            Expect(comp.Watermarks.Count, Is.EqualTo(2));

            comp.AddWatermark(enc);
            Expect(comp.Watermarks.Count, Is.EqualTo(3));

            Watermarker.EmbedWatermark(file, comp, "password", "results/CompositeMark.png");


            PNGFile file2 = new PNGFile("results/CompositeMark.png");

            CompositeWatermark extract = (CompositeWatermark)Watermarker.ExtractWatermark(file2, "password");


            System.Collections.Generic.List <Watermark> marks = extract.Watermarks;

            Expect(marks.Count, Is.EqualTo(3));

            Assert.IsInstanceOf <TextWatermark>(marks[0]);

            Assert.IsInstanceOf <TextWatermark>(marks[1]);

            Assert.IsInstanceOf <EncryptedWatermark>(marks[2]);



            ((EncryptedWatermark)marks[2]).Decrypt("supersecret");

            Expect(((TextWatermark)marks[0]).Text, Is.EqualTo("This is mark #1"));
            Expect(((TextWatermark)marks[1]).Text, Is.EqualTo("This is mark #2"));
            Expect(((EncryptedWatermark)marks[2]).Decrypt <TextWatermark>("supersecret").Text, Is.EqualTo("This is mark #1"));
        }
예제 #7
0
        public void TestDoubleEncrypt()
        {
            EncryptedWatermark.Algorithm = aes;

            TextWatermark      mark = new TextWatermark("This will be encrypted twice");
            EncryptedWatermark enc1 = new EncryptedWatermark(mark, "password1");
            EncryptedWatermark enc2 = new EncryptedWatermark(enc1, "password2");

            Watermarker.EmbedWatermark(file, enc2, "password", "results/DoubleEncrypt.png");

            PNGFile file2 = new PNGFile("results/DoubleEncrypt.png");

            EncryptedWatermark extract = Watermarker.ExtractWatermark <EncryptedWatermark>(file, "password");

            extract = extract.Decrypt <EncryptedWatermark>("password2");


            mark = extract.Decrypt <TextWatermark>("password1");

            Expect(mark.Text, Is.EqualTo("This will be encrypted twice"));
        }
예제 #8
0
        public void TestSeperateMarks()
        {
            // This will only pass if the marks do not overlap on any pixels.

            TextWatermark text1 = new TextWatermark("text1");
            TextWatermark text2 = new TextWatermark("text2");

            Watermarker.EmbedWatermark(file, text1, "password", "results/Embed1.png");

            file = new PNGFile("results/Embed1.png");

            Watermarker.EmbedWatermark(file, text2, "foobar", "results/Embed2Marks.png");

            PNGFile file2 = new PNGFile("results/Embed2Marks.png");

            TextWatermark extract1 = (TextWatermark)Watermarker.ExtractWatermark(file2, "password");

            TextWatermark extract2 = (TextWatermark)Watermarker.ExtractWatermark(file2, "foobar");

            Expect(extract1.Text, Is.EqualTo("text1"));
            Expect(extract2.Text, Is.EqualTo("text2"));
        }
예제 #9
0
        public void TestLongRSWatermark()
        {
            byte[] data = new byte[300];
            for (var x = 0; x < 300; x++)
            {
                data[x] = (byte)(x % 17);
            }

            BinaryWatermark binMark = new BinaryWatermark(data);

            Watermarker.ReedSolomonProtection = true;

            Watermarker.EmbedWatermark(file, binMark, "password", "results/LongRS.png");

            PNGFile file2 = new PNGFile("results/LongRS.png");

            BinaryWatermark binMark2 = Watermarker.ExtractWatermark <BinaryWatermark>(file2, "password");

            for (var x = 0; x < binMark2.data.Length; x++)
            {
                Expect(binMark2.data[x], Is.EqualTo(binMark.data[x]));
            }
        }
예제 #10
0
        static void Main(string[] args)
        {
            //bool goodArgs = parseArgs(new string[]{"-m=EMBED", "-i=TestImage.png", "-o=Output.png", "-p=password", "-t=Hello", "-t=World", "-f=TestFile.txt", "-f=TestFile.txt", "-b=03,2A,4C,BD", "-e", "-a=AES", "-k=supersecret"});
            //bool goodArgs = parseArgs(new string[] { "-m=EXTRACT","-c","-i=Output.png", "-p=password", "-t=Hello", "-t=World", "-f=TestFile.txt", "-f=TestFile.txt", "-b=03,2A,4C,BD", "-e", "-a=AES", "-k=supersecret" });
            bool goodArgs = parseArgs(args);

            if (goodArgs)
            {
                Watermarker.ReedSolomonProtection = ReedSolomon;

                if (Encrypt)
                {
                    SymmetricAlgorithm algo = null;
                    switch (Algorithm)
                    {
                    case "AES":
                        algo = new RijndaelManaged();
                        break;
                    }
                    if (algo != null)
                    {
                        algo.Padding = PaddingMode.Zeros;
                    }
                    else
                    {
                        Console.WriteLine("Invalid Algorithm specified, valid options are [\"AES\"]");
                        return;
                    }

                    EncryptedWatermark.Algorithm = algo;
                }

                if (Mode.Equals("EMBED"))
                {
                    Watermark finalMark;

                    if (marks.Count > 1)
                    {
                        CompositeWatermark comp = new CompositeWatermark();

                        foreach (Watermark m in marks)
                        {
                            comp.AddWatermark(m);
                        }
                        finalMark = comp;
                    }
                    else
                    {
                        finalMark = marks[0];
                    }

                    if (Encrypt)
                    {
                        finalMark = new EncryptedWatermark(finalMark, EncKey);
                    }

                    PNGFile fileIn = new PNGFile(InputFile);

                    Watermarker.EmbedWatermark(fileIn, finalMark, Password, OutputFile);
                }
                else
                {
                    PNGFile fileIn = new PNGFile(InputFile);

                    Watermark        mark  = Watermarker.ExtractWatermark(fileIn, Password);
                    List <Watermark> marks = new List <Watermark>();

                    // check to see if encrypted
                    if (mark.GetType().Equals(typeof(EncryptedWatermark)))
                    {
                        Console.WriteLine("Detected an encrypted watermark.");
                        if (Encrypt)
                        {
                            Console.WriteLine("Attempting to decrypt the watermark...");
                            mark = ((EncryptedWatermark)mark).Decrypt(EncKey);
                        }
                        else
                        {
                            Console.WriteLine("Encrypt flag was not set, unable to continue. Please try again with the -e flag and appropriate -a and -k values");
                            return;
                        }
                    }

                    // check to see if it is a composite
                    if (mark.GetType().Equals(typeof(CompositeWatermark)))
                    {
                        Console.WriteLine("Composite Watermark detected.");

                        CompositeWatermark comp = (CompositeWatermark)mark;

                        Console.WriteLine("Total of " + comp.Watermarks.Count + " Watermarks found.");

                        foreach (Watermark m in comp.Watermarks)
                        {
                            marks.Add(m);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Found 1 watermark.");
                        marks.Add(mark);
                    }

                    // check to see if only console output
                    if (OnlyConsole)
                    {
                        foreach (Watermark m in marks)
                        {
                            Console.WriteLine(m);
                        }
                    }
                    else
                    {
                        for (var x = 0; x < marks.Count; x++)
                        {
                            marks[x].Save(OutputFile + "\\" + "Watermark" + (x + 1));
                        }
                    }
                }
            }
            Console.ReadKey();
        }