Exemple #1
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();
        }