Beispiel #1
0
        public T Decrypt <T>(string password)
        {
            Watermark m = Decrypt(password);

            T retVal = default(T);

            try
            {
                retVal = (T)Convert.ChangeType(m, typeof(T));
            }
            catch (Exception ex) { }

            return(retVal);
        }
Beispiel #2
0
        internal static CompositeWatermark LoadFromBytes(byte[] data)
        {
            CompositeWatermark comp = new CompositeWatermark();

            MemoryStream ms = new MemoryStream(data);

            byte[] type  = new byte[1];
            byte[] dword = new byte[4];
            byte[] markData;
            while (ms.Position < ms.Length)
            {
                ms.Read(type, 0, 1);
                ms.Read(dword, 0, 4);

                markData = new byte[BitConverter.ToInt32(dword, 0)];
                ms.Read(markData, 0, markData.Length);
                Watermark mark = null;
                switch (type[0])
                {
                case 1:
                    mark = TextWatermark.LoadFromBytes(markData);
                    break;

                case 2:
                    mark = FileWatermark.LoadFromBytes(markData);
                    break;

                case 3:
                    mark = BinaryWatermark.LoadFromBytes(markData);
                    break;

                case 4:
                    mark = CompositeWatermark.LoadFromBytes(markData);
                    break;

                case 9:
                    mark = EncryptedWatermark.LoadFromBytes(markData);
                    break;
                }

                comp.watermarks.Add(mark);
            }
            return(comp);
        }
Beispiel #3
0
        /// <summary>
        /// Constructor for an encrypted watermark.
        /// </summary>
        /// <param name="mark">The watermark to encrypt.</param>
        /// <param name="password">The password which is used to derive the encryption key.</param>
        public EncryptedWatermark(Watermark mark, string password)
        {
            /*if (mark.GetMarkType() == this.GetMarkType())
             * {
             *  throw new ArgumentException("You cannot next encrypted watermarks!");
             * }*/
            // get the base marks bytes
            byte[] markBytes = mark.GetBytes();

            bytes     = new Rfc2898DeriveBytes(password, 8);
            this.salt = bytes.Salt;

            key = bytes.GetBytes(Algorithm.KeySize / 8);

            if (Algorithm.IV == null)
            {
                Algorithm.IV = bytes.GetBytes(Algorithm.BlockSize);
            }
            Algorithm.Key = key;
            byte[] iv = Algorithm.IV;

            byte[] cryptData = Encrypt(markBytes, Algorithm);

            MemoryStream ms = new MemoryStream();

            byte[] ivLength = BitConverter.GetBytes(iv.Length);
            ms.Write(ivLength, 0, ivLength.Length);

            ms.Write(iv, 0, iv.Length);

            byte[] dataLength = BitConverter.GetBytes(cryptData.Length);
            ms.Write(dataLength, 0, dataLength.Length);

            ms.Write(cryptData, 0, cryptData.Length);

            cryptedData = ms.ToArray();
        }
Beispiel #4
0
 public void RemoveWatermark(Watermark mark)
 {
     watermarks.Remove(mark);
 }
Beispiel #5
0
 public void AddWatermark(Watermark mark)
 {
     watermarks.Add(mark);
 }