예제 #1
0
파일: Album.cs 프로젝트: altaria/Altaria
        public int retrieveAlbumId()
        {
            DBConnect connection = new DBConnect();

            string query = "SELECT albumId FROM Album WHERE albumName LIKE @albumName;";

            try
            {
                MySqlCommand cmd = new MySqlCommand(query, connection.OpenConnection());
                cmd.CommandText = query;
                cmd.Prepare();
                cmd.Parameters.AddWithValue("@albumName", this.albumName);

                albumId = int.Parse(cmd.ExecuteScalar() + "");

                cmd.ExecuteNonQuery();

                connection.CloseConnection();

                return albumId;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }
예제 #2
0
        public bool insertNewImage()
        {
            DBConnect connection = new DBConnect();

            string query = "INSERT INTO image(imageTitle, imageAuthor, digestId, digestHash) VALUES(@imageTitle, @imageAuthor, @digestId, @hash)";

            try
            {
                MySqlCommand cmd = new MySqlCommand(query, connection.OpenConnection());
                cmd.CommandText = query;
                cmd.Prepare();
                cmd.Parameters.AddWithValue("@imageTitle", this.imageTitle);
                cmd.Parameters.AddWithValue("@imageAuthor", this.imageAuthor);
                if (!string.IsNullOrEmpty(digestId))
                    cmd.Parameters.AddWithValue("@digestId", this.digestId);
                else
                    cmd.Parameters.AddWithValue("@digestId", "n");
                cmd.Parameters.AddWithValue("@hash", this.hash);

                cmd.ExecuteNonQuery();

                query = "SELECT LAST_INSERT_ID();";
                cmd.CommandText = query;
                cmd.Prepare();

                int imageId = Convert.ToInt32(cmd.ExecuteScalar());

                for (int i = 0; i < digestCoeffs.Count(); i++)
                {
                    query = "INSERT INTO imageCoeffs(imageId, value) VALUES(@imageId, @value);";
                    cmd.CommandText = query;
                    cmd.Prepare();
                    cmd.Parameters.AddWithValue("@imageId", imageId);
                    cmd.Parameters.AddWithValue("@value", digestCoeffs[i]);

                    cmd.ExecuteNonQuery();

                    cmd.Parameters.Clear();
                }

                connection.CloseConnection();

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
예제 #3
0
파일: Album.cs 프로젝트: altaria/Altaria
        public bool InsertAlbum()
        {
            DBConnect connection = new DBConnect();

            string query = "INSERT INTO Album(albumName) VALUES(@albumName);";

            try
            {
                MySqlCommand cmd = new MySqlCommand(query, connection.OpenConnection());
                cmd.CommandText = query;
                cmd.Prepare();
                cmd.Parameters.AddWithValue("@albumName", this.albumName);

                cmd.ExecuteNonQuery();

                connection.CloseConnection();

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
예제 #4
0
파일: Album.cs 프로젝트: altaria/Altaria
        public bool UpdateAlbum()
        {
            DBConnect connection = new DBConnect();

            string query = "UPDATE Album SET albumName=@albumName WHERE albumId=@id;";

            try
            {
                MySqlCommand cmd = new MySqlCommand(query, connection.OpenConnection());
                cmd.CommandText = query;
                cmd.Prepare();
                cmd.Parameters.AddWithValue("@albumName", this.albumName);
                cmd.Parameters.AddWithValue("@id", this.albumId);

                cmd.ExecuteNonQuery();

                connection.CloseConnection();

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
예제 #5
0
        public ArrayList retrieveAllHashes()
        {
            DBConnect connection = new DBConnect();
            ArrayList imageFingerprint = new ArrayList();
            string query = "SELECT i.imageId, i.imageTitle, i.imageAuthor, i.digestId, i.digestHash, ic.value FROM image i INNER JOIN imageCoeffs ic ON i.imageId = ic.imageId;";

            try
            {
                MySqlCommand cmd = new MySqlCommand(query, connection.OpenConnection());
                cmd.CommandText = query;
                cmd.Prepare();

                MySqlDataReader dataReader = cmd.ExecuteReader();
                int i = 0;
                byte[] digestCoeffs = new byte[40];

                while (dataReader.Read())
                {
                    int imageId = (int)dataReader[0];
                    string imageTitle = (string)dataReader[1];
                    string imageAuthor = (string)dataReader[2];
                    string digestId = (string)dataReader[3];
                    ulong hash = (ulong)dataReader[4];

                    if (digestId.Equals("n"))
                        digestId = null;

                    int temp = (int)dataReader[5];
                    digestCoeffs[i] = (byte)temp;
                    i++;

                    if (i == 40)
                    {
                        ImageFingerprint image = new ImageFingerprint(imageTitle, imageAuthor, digestId, digestCoeffs, hash);
                        imageFingerprint.Add(image);
                        i = 0;
                        digestCoeffs = new byte[40];
                    }
                }

                return imageFingerprint;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
예제 #6
0
        public static string verifyWatermark(List<Complex[]> complexframes1, List<Complex[]> complexframes2, int userid, string filename, string watermarkpath)
        {
            int shorter;
            if (complexframes1[0].Length >= complexframes2[0].Length)
            { shorter = complexframes2[0].Length; }
            else { shorter = complexframes1[0].Length; }

            string storedkey = "";
            string name = "";
            string regno = "";
            string address = "";
            string contact = "";
            string keyinfo = "";
            string datakey = "";
            DBConnect connection = new DBConnect();

            string query = "SELECT keydata.keydatadata, userdata.userdataname, userdata.userdataregno, userdata.userdataaddress, userdata.userdatacontact, keydata.keydatainfo, keydata.keydatakey FROM keydata INNER JOIN userdata ON keydata.iduserdata = userdata.iduserdata WHERE (keydata.iduserdata = @userid) AND (keydata.keysongname = @songname)";

            try
            {
                MySqlCommand cmd = new MySqlCommand(query, connection.OpenConnection());
                cmd.CommandText = query;
                cmd.Prepare();
                cmd.Parameters.AddWithValue("@userid", userid);
                cmd.Parameters.AddWithValue("@songname", filename);
                MySqlDataReader Reader = cmd.ExecuteReader();
                if (!Reader.HasRows) return "No Matches found in Database!";
                while (Reader.Read())
                {
                    name = KeyGen.GetDBString("userdataname", Reader);
                    regno = KeyGen.GetDBString("userdataregno", Reader);
                    storedkey = KeyGen.GetDBString("keydatadata", Reader);
                    address = KeyGen.GetDBString("userdataaddress", Reader);
                    contact = KeyGen.GetDBString("userdatacontact", Reader);
                    keyinfo = KeyGen.GetDBString("keydatainfo", Reader);
                    datakey = KeyGen.GetDBString("keydatakey", Reader);
                }
                Reader.Close();
                connection.CloseConnection();

            }
            catch (Exception ex)
            {
            }

            if (!storedkey.Equals("") && (storedkey != null))
            {
                double[] d = KeyGen.StringToDoubleArr(storedkey);

                double[] weight = new double[5];
                double avg = 0;

                for (int h = 0; h < complexframes1.Count; h++)
                {

                    Complex[] difference = new Complex[shorter];
                    for (int i = 0; i < 5; i++)
                    {
                        difference[i] = complexframes2[h][i] - complexframes1[h][i];
                        weight[i] = difference[i].Real / d[i];
                    }
                    avg = avg + weight.Average();

                }
                avg = avg / complexframes1.Count;

                StringBuilder strOutputInfo = new StringBuilder();
                //if (Math.Abs(avg) >= 0.7 && Math.Abs(avg) <= 1.51)
                Debug.WriteLine(datakey);
                Debug.WriteLine(KeyGen.ToHex(MD5.Create().ComputeHash(File.ReadAllBytes(watermarkpath)), true));
                byte[] computedkeydata = MD5.Create().ComputeHash(File.ReadAllBytes(watermarkpath));
                if (datakey.Equals(KeyGen.ToHex(MD5.Create().ComputeHash(File.ReadAllBytes(watermarkpath)),true)))
                {
                    strOutputInfo.Append("Watermark is Verified<br />");
                    strOutputInfo.Append("Registered User : "******"<br />");
                    strOutputInfo.Append("Registration # : " + regno + "<br />");
                    strOutputInfo.Append("User's Contact : " + contact + "<br />");
                    strOutputInfo.Append("User's Address : " + address + "<br />");
                    strOutputInfo.Append("Watermark Info : " + keyinfo + "<br />");
                    return strOutputInfo.ToString();
                }
                else
                {
                    strOutputInfo.Append("Watermark is Rejected");
                    return strOutputInfo.ToString();
                }
            }
            else
            {
                return "No Matches found in Database!";
            }
        }
예제 #7
0
        public List<Complex[]> readAudio(int userid, int frameLength, int mode)
        {
            //mode1 embed ; mode2 verify
            byte[] file = fileReader();
            bytestodata = KeyGen.SimpleBoyerMooreSearch(file, datasection);

            subchunksize = new byte[4];
            subchunksize[0] = file[16];
            subchunksize[1] = file[17];
            subchunksize[2] = file[18];
            subchunksize[3] = file[19];

            //converting file into double[]
            int headerLength = audioHeaderLength();
            double[] x = ByteToDouble(file, headerLength);
            Debug.WriteLine("Header Length : " + headerLength);

            //convert double[] into complex[]
            Complex[] samples = DoubleToComplex(x);
            Debug.WriteLine("samples.Length " + samples.Length);

            //split complex[] into frames

            var frames = samples.Batch(frameLength);
            int frameCount = 0;
            int remainder = 0;
            List<Complex[]> complexframes = new List<Complex[]>();
            foreach (var batch in frames)
            {
                remainder = batch.Count();
                frameCount++;
                foreach (var frame in batch)
                {
                }
                complexframes.Add(batch.ToArray());
            }

            Debug.WriteLine("Before Fourier Transform Forward");
            foreach (var frame in complexframes)
            {
                Transform.FourierForward(frame);
            }

            if (mode == 1 && userid != 0)
            {
                //embedwatermark
                KeyGen key = new KeyGen(userid, frameLength, frameCount, name);
                complexframes = embedWatermark(complexframes, key);

                //convert complex[] to byte[]
                byte[] output = new byte[((frameCount - 1) * frameLength) + remainder + headerLength];
                int bytecounter = 0;
                foreach (var frame in complexframes)
                {
                    foreach (var singlecomplex in frame)
                    {
                        output[bytecounter + headerLength] = (byte)(Convert.ToInt16(singlecomplex.Real * 32768.0));
                        bytecounter++;
                    }
                }

                for (int i = 0; i < headerLength - 1; i++)
                {
                    output[i] = file[i];
                }

                Debug.WriteLine("Writing new file : " + path + "new_" + name);
                ByteArrayToFile(path + "new_" + name, output);

                Debug.WriteLine("File Successfully written");

                DBConnect connection = new DBConnect();

                string query = "UPDATE keydata SET keydatakey=@datakey where (iduserdata=@userid) and (keysongname=@name) ";

                try
                {
                    MySqlCommand cmd = new MySqlCommand(query, connection.OpenConnection());
                    cmd.CommandText = query;
                    cmd.Prepare();
                    cmd.Parameters.AddWithValue("@datakey", KeyGen.ToHex(MD5.Create().ComputeHash(File.ReadAllBytes(path + "new_" + name)),true));
                    cmd.Parameters.AddWithValue("@userid", userid);
                    cmd.Parameters.AddWithValue("@name", name);
                    Debug.WriteLine(MD5.Create().ComputeHash(File.ReadAllBytes(path + "new_" + name)));

                    cmd.ExecuteNonQuery();

                    connection.CloseConnection();

                }
                catch (Exception ex)
                {
                    Debug.WriteLine("SQL INSERT INTO KEYDATA FAILED!");
                }

                return null;
            }
            return complexframes;
        }
예제 #8
0
        public SongRetrieval retrieveSongFromSongId()
        {
            SongRetrieval sr = null;
            DBConnect connection = new DBConnect();

            string query = "SELECT s.songTitle, ar.artistName, al.albumName FROM song s INNER JOIN artist ar ON s.artistId = ar.artistId INNER JOIN album al ON s.albumId = al.albumId WHERE s.songId = @songId;";

            try
            {
                MySqlCommand cmd = new MySqlCommand(query, connection.OpenConnection());
                cmd.CommandText = query;
                cmd.Prepare();
                cmd.Parameters.AddWithValue("@songId", this.songId);

                //string songTitle = (string)cmd.ExecuteScalar();
                MySqlDataReader dataReader = cmd.ExecuteReader();

                while(dataReader.Read())
                    sr = new SongRetrieval((string)dataReader[0], (string)dataReader[1], (string)dataReader[2]);

                connection.CloseConnection();

                return sr;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
예제 #9
0
파일: KeyGen.cs 프로젝트: altaria/Altaria
        public List<Complex[]> embedWatermark(List<Complex[]> complexframes)
        {
            foreach (var frame in complexframes)
            {

                frame[0] = frame[0] + keydatadatadouble[0];
                frame[1] = frame[1] + keydatadatadouble[1];
                frame[2] = frame[2] + keydatadatadouble[2];
                frame[3] = frame[3] + keydatadatadouble[3];
                frame[4] = frame[4] + keydatadatadouble[4];
                Transform.FourierInverse(frame);

            }
            keydatainfo = keydatainfo + " | Key Embedded on " + DateTime.Now;

            DBConnect connection = new DBConnect();

            string query = "INSERT INTO keydata(iduserdata,keydatadata,keydatainfo,keyframelength,keysongname) VALUES (@userid, @keydata, @keydatainfo, @keyframelength, @songname)";

            try
            {
                MySqlCommand cmd = new MySqlCommand(query, connection.OpenConnection());
                cmd.CommandText = query;
                cmd.Prepare();
                cmd.Parameters.AddWithValue("@userid", this.userdata);
                //cmd.Parameters.AddWithValue("@keydata", ComplexArrToString(this.keydatadata));
                cmd.Parameters.AddWithValue("@keydata", String.Join(",", keydatadatadouble.Select(p => p.ToString()).ToArray()));
                cmd.Parameters.AddWithValue("@keydatainfo", this.keydatainfo);
                cmd.Parameters.AddWithValue("@keyframelength", this.keyframelength);
                cmd.Parameters.AddWithValue("@songname", this.name);
                cmd.ExecuteNonQuery();

                connection.CloseConnection();

            }
            catch (Exception ex)
            {
                Debug.WriteLine("SQL INSERT INTO KEYDATA FAILED!");
            }

            return complexframes;
        }
예제 #10
0
        public string retrieveSongFromHashId()
        {
            DBConnect connection = new DBConnect();

            string query = "SELECT songTitle FROM song s INNER JOIN songhash sh ON sh.songId = s.songId WHERE sh.hashId = @hashId;";

            try
            {
                MySqlCommand cmd = new MySqlCommand(query, connection.OpenConnection());
                cmd.CommandText = query;
                cmd.Prepare();
                cmd.Parameters.AddWithValue("@hashId", this.songHashId);

                string songTitle = (string)cmd.ExecuteScalar();

                connection.CloseConnection();

                return songTitle;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
예제 #11
0
        public int retrieveLatestSongId()
        {
            DBConnect connection = new DBConnect();

            string query = "SELECT max(songId) FROM song;";

            try
            {
                MySqlCommand cmd = new MySqlCommand(query, connection.OpenConnection());
                cmd.CommandText = query;
                cmd.Prepare();

                songId = int.Parse(cmd.ExecuteScalar() + "");

                connection.CloseConnection();

                return songId;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }
예제 #12
0
        /*public void retrieveAllHash()
        {
            DBConnect connection = new DBConnect();
            ArrayList hashValues = new ArrayList();

            string query = "SELECT hashId, songHash FROM songhash;";

            try
            {
                MySqlCommand cmd = new MySqlCommand(query, connection.OpenConnection());
                cmd.CommandText = query;
                cmd.Prepare();

                MySqlDataReader dataReader = cmd.ExecuteReader();

                hashId = new ArrayList();
                hashValues = new ArrayList();

                while (dataReader.Read())
                {
                    hashId.Add(dataReader[0]);
                    hashValues.Add(dataReader[1]);
                }

                this.setHashId(hashId);
                this.setSongHashes(hashValues);

                connection.CloseConnection();
            }
            catch (Exception ex)
            {

            }
        }*/
        public void retrieveAllHash()
        {
            DBConnect connection = new DBConnect();
            ArrayList hashValues = new ArrayList();

            string query = "SELECT songId, songHash FROM songhash;";

            try
            {
                MySqlCommand cmd = new MySqlCommand(query, connection.OpenConnection());
                cmd.CommandText = query;
                cmd.Prepare();

                MySqlDataReader dataReader = cmd.ExecuteReader();

                songIdList = new ArrayList();
                hashValues = new ArrayList();

                while (dataReader.Read())
                {
                    songIdList.Add(dataReader[0]);
                    hashValues.Add(dataReader[1]);
                }

                this.setSongIdList(songIdList);
                this.setSongHashes(hashValues);

                connection.CloseConnection();
            }
            catch (Exception ex)
            {

            }
        }
예제 #13
0
        public bool InsertSongHash()
        {
            DBConnect connection = new DBConnect();

            string query = "INSERT INTO songhash(songId, songHash, songOffset) VALUES(@songId, @songHash, @songOffset);";

            try
            {
                MySqlCommand cmd = new MySqlCommand(query, connection.OpenConnection());
                cmd.CommandText = query;
                cmd.Prepare();
                cmd.Parameters.AddWithValue("@songId", this.songId);
                cmd.Parameters.AddWithValue("@songHash", this.songHash);
                cmd.Parameters.AddWithValue("@songOffset", this.songOffset);

                cmd.ExecuteNonQuery();

                connection.CloseConnection();

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
예제 #14
0
        public bool InsertSong()
        {
            DBConnect connection = new DBConnect();

            string query = "INSERT INTO song(artistId, albumId, songTitle, songBitrate) VALUES(@artistId, @albumId, @songTitle, @songBitrate);";

            try
            {
                MySqlCommand cmd = new MySqlCommand(query, connection.OpenConnection());
                cmd.CommandText = query;
                cmd.Prepare();
                cmd.Parameters.AddWithValue("@artistId", this.artistId);
                cmd.Parameters.AddWithValue("@albumId", this.albumId);
                cmd.Parameters.AddWithValue("@songTitle", this.songTitle);
                cmd.Parameters.AddWithValue("@songBitrate", this.songBitrate);

                cmd.ExecuteNonQuery();

                connection.CloseConnection();

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }