Пример #1
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"));
        }
Пример #2
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"));
        }
Пример #3
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]));
            }
        }
Пример #4
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();
        }