Example #1
0
        private void button8_Click(object sender, EventArgs e)
        {
            hasher h      = new hasher();
            string output = h.rinjdael_encode(textBox1.Text, "password");

            textBox2.Text = output;
        }
Example #2
0
        public void Sha256Test()
        {
            hasher h      = new hasher();
            string hash   = h.sha256("A quick brown fox jumps over the lazy dog.");
            string expect = "��%��ԄnL�u�\u0003��\u000f�Vj���W\u0014X��P��";

            Assert.AreEqual(expect, hash);
        }
Example #3
0
        public void Sha512Test()
        {
            hasher h      = new hasher();
            string hash   = h.sha512("A quick brown fox jumps over the lazy dog.");
            string expect = @"0EW\�s�eo_4&�JJ���S�r��p������ʴ�����?��J�SjBsS�t��e��F";

            Assert.AreEqual(expect, hash);
        }
Example #4
0
        private void button7_Click(object sender, EventArgs e)
        {
            hasher h      = new hasher();
            string output = h.sha512ascii(textBox1.Text);

            //sha512ascii sha = new sha512ascii();
            //string output = sha.encode(textBox1.Text);

            textBox2.Text = output;
        }
Example #5
0
        private void button3_Click(object sender, EventArgs e)
        {
            hasher h      = new hasher();
            string output = h.md5(textBox1.Text);

            //md5 md5 = new md5();
            //string output = md5.encode(textBox1.Text);

            textBox2.Text = output;
        }
Example #6
0
        private void button2_Click(object sender, EventArgs e)
        {
            hasher h      = new hasher();
            string output = h.base64_decode(textBox2.Text);

            //base64 bs = new base64();
            //string output = bs.decode(textBox2.Text);

            textBox1.Text = output;
        }
Example #7
0
        public void rinjdael_decodeTest()
        {
            string orignal = "I am a test.";

            hasher h       = new hasher();
            string cypher  = h.rinjdael_encode(orignal);
            string decoded = h.rinjdael_decode(cypher);

            Assert.AreEqual(orignal, decoded);
            Assert.AreNotEqual(cypher, decoded);
        }
Example #8
0
        public void Base64DecodeTest()
        {
            /**
             * SQL: SELECT FROM_BASE64("QSBxdWljayBicm93biBmb3gganVtcHMgb3ZlciB0aGUgbGF6eSBkb2cu");
             * PHP: php -r "echo base64_decode('QSBxdWljayBicm93biBmb3gganVtcHMgb3ZlciB0aGUgbGF6eSBkb2cu');"
             *
             * A quick brown fox jumps over the lazy dog.
             */
            hasher h        = new hasher();
            string original = h.base64_decode("QSBxdWljayBicm93biBmb3gganVtcHMgb3ZlciB0aGUgbGF6eSBkb2cu");
            string expect   = "A quick brown fox jumps over the lazy dog.";

            Assert.AreEqual(expect, original);
        }
Example #9
0
        public void Base64EncodeTest()
        {
            /**
             * SQL: SELECT TO_BASE64("A quick brown fox jumps over the lazy dog.");
             * PHP: php -r "echo base64_encode('A quick brown fox jumps over the lazy dog.');"
             *
             * QSBxdWljayBicm93biBmb3gganVtcHMgb3ZlciB0aGUgbGF6eSBkb2cu
             */
            hasher h      = new hasher();
            string hash   = h.base64_encode("A quick brown fox jumps over the lazy dog.");
            string expect = "QSBxdWljayBicm93biBmb3gganVtcHMgb3ZlciB0aGUgbGF6eSBkb2cu";

            Assert.AreEqual(expect, hash);
        }
Example #10
0
        public void Sha256AsciiTest()
        {
            /**
             * PHP: php -r "echo hash('sha256', 'A quick brown fox jumps over the lazy dog.');"
             * SQL: SELECT SHA2('A quick brown fox jumps over the lazy dog.', 256);
             *
             * ffca2587cfd4846e4cb975b503c9eb940f94566aa394e8bd571458b9da5097d5
             */
            hasher h      = new hasher();
            string hash   = h.sha256ascii("A quick brown fox jumps over the lazy dog.");
            string expect = "ffca2587cfd4846e4cb975b503c9eb940f94566aa394e8bd571458b9da5097d5";

            Assert.AreEqual(expect, hash);
        }
Example #11
0
        public void md5Test()
        {
            /**
             * SQL: SELECT MD5("A quick brown fox jumps over the lazy dog.");
             * PHP: php -r "echo md5('A quick brown fox jumps over the lazy dog.');"
             * PHP: php -r "echo hash('md5', 'A quick brown fox jumps over the lazy dog.');"
             *
             * df756a3769fcab0a261880957590c768
             */
            hasher h      = new hasher();
            string hash   = h.md5("A quick brown fox jumps over the lazy dog.");
            string expect = "df756a3769fcab0a261880957590c768";

            Assert.AreEqual(expect, hash);
        }
Example #12
0
        public void md5UnicodeTest()
        {
            /**
             * SQL: SELECT MD5('क का कि की कु कू के कै को कौ');
             *
             * c55a55aff4906fa6b2d3c901c63dea47
             */
            string orignal = "क का कि की कु कू के कै को कौ";

            hasher h      = new hasher();
            string hash   = h.md5(orignal);
            string expect = "c55a55aff4906fa6b2d3c901c63dea47";

            Assert.AreEqual(expect, hash);
        }
Example #13
0
        public void rinjdael_modifiedPasswordCannotDecrypt()
        {
            string orignal  = "I am a test.";
            string password = "******";

            hasher h      = new hasher();
            string cypher = h.rinjdael_encode(orignal, password);

            // password is modified here
            string decoded1 = h.rinjdael_decode(cypher, password + " ");
            string decoded2 = h.rinjdael_decode(cypher, password);

            Assert.AreNotEqual(orignal, decoded1);
            Assert.AreEqual(orignal, decoded2);
        }
Example #14
0
        public void des_decode()
        {
            string orignal = "I am a test.";

            for (int i = 0; i < 20; ++i)
            {
                orignal += string.Format("#{0}. {1}", i, orignal);
            }

            hasher h       = new hasher();
            string cypher  = h.des_encode(orignal);
            string decoded = h.des_decode(cypher);

            Assert.AreEqual(orignal, decoded);
            Assert.AreNotEqual(cypher, decoded);
        }
Example #15
0
        public void Base64UnicodeTest()
        {
            /**
             * SQL: SELECT TO_BASE64('क का कि की कु कू के कै को कौ');
             * PHP: php -r "echo base64_decode('क का कि की कु कू के कै को कौ');" -- failing
             *
             * SQL: SELECT TO_BASE64('क का कि की कु कू के कै को कौ');
             * 4KSVIOCkleCkviDgpJXgpL8g4KSV4KWAIOCkleClgSDgpJXgpYIg4KSV4KWHIOCkleCliCDgpJXgpYsg4KSV4KWM
             */
            string original       = "क का कि की कु कू के कै को कौ";
            string expect_encoded = "4KSVIOCkleCkviDgpJXgpL8g4KSV4KWAIOCkleClgSDgpJXgpYIg4KSV4KWHIOCkleCliCDgpJXgpYsg4KSV4KWM";

            hasher h       = new hasher();
            string encoded = h.base64_encode(original);
            string decoded = h.base64_decode(encoded);

            Assert.AreEqual(expect_encoded, encoded);
            Assert.AreEqual(original, decoded);
        }
Example #16
0
        public void rinjdael_decodeLongTextTest()
        {
            string password = "******";

            // generates a very long text
            string orignal = "A Quick Brown Fox Jumps Over The Lazy Dog.";

            for (int i = 0; i < 20; ++i)
            {
                orignal += string.Format("#{0}. {1}", i, orignal);
            }

            hasher h       = new hasher();
            string cypher  = h.rinjdael_encode(orignal, password);
            string decoded = h.rinjdael_decode(cypher, password);

            Assert.AreEqual(orignal, decoded);
            Assert.AreNotEqual(cypher, decoded);
        }
Example #17
0
        public void ShaUnicdoeTest()
        {
            /**
             * @see https://dev.mysql.com/doc/refman/5.7/en/encryption-functions.html#function_sha2
             * @see https://dev.mysql.com/doc/refman/8.0/en/encryption-functions.html
             *
             * SQL: SELECT SHA2('क का कि की कु कू के कै को कौ', 512);
             * SQL: SELECT SHA2('क का कि की कु कू के कै को कौ', 256);
             * SQL: SELECT SHA1('क का कि की कु कू के कै को कौ');
             *
             * 31998db2c979957bd4930d08413b5bcebd0b2607f1bc9eefdd76db98dd63b3a3d6b513875b2d954053a60a0d626dab205c0a2e860e3ce090a3071db4a2c352da
             */
            string original = "क का कि की कु कू के कै को कौ";

            hasher h      = new hasher();
            string hash   = h.sha512ascii(original);
            string expect = "3534e6cb0c8f2760709528c7713055122c340361";

            Assert.AreEqual(expect, hash);
        }
Example #18
0
        public void Sha512AsciiTest()
        {
            /**
             * PHP: php -r "echo hash('sha512', 'A quick brown fox jumps over the lazy dog.');"
             * SQL: SELECT SHA2('A quick brown fox jumps over the lazy dog.', 512);
             *
             * DECLARE @HashThis NVARCHAR(4000);
             * SET @HashThis = CONVERT(NVARCHAR(4000), 'A quick brown fox jumps over the lazy dog.');
             * SELECT HASHBYTES('SHA1', @HashThis);
             *
             * @see https://dev.mysql.com/doc/refman/5.5/en/encryption-functions.html
             * @see https://docs.microsoft.com/en-us/sql/t-sql/functions/hashbytes-transact-sql
             *
             * 3045575cf3b873dd656f5f3426e04a4acd11950bb2538772ee14867002b408e21ff18ef7f7b2cab484a3c1c0be3f8acc4aed536a427353c7748dc365fc1a8646
             */
            hasher h      = new hasher();
            string hash   = h.sha512ascii("A quick brown fox jumps over the lazy dog.");
            string expect = "3045575cf3b873dd656f5f3426e04a4acd11950bb2538772ee14867002b408e21ff18ef7f7b2cab484a3c1c0be3f8acc4aed536a427353c7748dc365fc1a8646";

            Assert.AreEqual(expect, hash);
        }