Esempio n. 1
0
        /// <summary>KeyedHash</summary>
        private static void KeyedHash()
        {
            string data = "ynyKeiR9FXWPkNQHvUPZkAlfUmouExBv";
            string key  = "ynyKeiR9FXWPkNQHvUPZkAlfUmouExBv";

            MyDebug.OutputDebugAndConsole("KeyedHashAlgorithm.Default", GetKeyedHash.GetKeyedHashString(data, EnumKeyedHashAlgorithm.Default, key));
            MyDebug.OutputDebugAndConsole("KeyedHashAlgorithm.HMACMD5", GetKeyedHash.GetKeyedHashString(data, EnumKeyedHashAlgorithm.HMACMD5, key));
            MyDebug.OutputDebugAndConsole("KeyedHashAlgorithm.HMACRIPEMD160", GetKeyedHash.GetKeyedHashString(data, EnumKeyedHashAlgorithm.HMACRIPEMD160, key));
            MyDebug.OutputDebugAndConsole("KeyedHashAlgorithm.HMACSHA1", GetKeyedHash.GetKeyedHashString(data, EnumKeyedHashAlgorithm.HMACSHA1, key));
            MyDebug.OutputDebugAndConsole("KeyedHashAlgorithm.HMACSHA256", GetKeyedHash.GetKeyedHashString(data, EnumKeyedHashAlgorithm.HMACSHA256, key));
            MyDebug.OutputDebugAndConsole("KeyedHashAlgorithm.HMACSHA384", GetKeyedHash.GetKeyedHashString(data, EnumKeyedHashAlgorithm.HMACSHA384, key));
            MyDebug.OutputDebugAndConsole("KeyedHashAlgorithm.HMACSHA512", GetKeyedHash.GetKeyedHashString(data, EnumKeyedHashAlgorithm.HMACSHA512, key));
            MyDebug.OutputDebugAndConsole("KeyedHashAlgorithm.MACTripleDES", GetKeyedHash.GetKeyedHashString(data, EnumKeyedHashAlgorithm.MACTripleDES, key));
        }
Esempio n. 2
0
        [TestCase(null, 999, "test@123", ExpectedException = typeof(ArgumentNullException), TestName = "TestID-018A")]       // The encryption method that is not defined
        public void GetKeyedHashStringTest(string sourceString, EnumKeyedHashAlgorithm eha, string password)
        {
            try
            {
                // Get the hash value using the components of touryo.
                string hashString = GetKeyedHash.GetKeyedHashString(sourceString, eha, password);

                // Using the components of touryo, and get the hash value again.
                string hashString2 = GetKeyedHash.GetKeyedHashString(sourceString, eha, password);

                // Check the hash value.
                Assert.AreNotEqual(sourceString, hashString);
                Assert.AreNotEqual(sourceString, hashString2);
                Assert.AreEqual(hashString, hashString2);
            }
            catch (Exception ex)
            {
                // Print a stack trace when an exception occurs.
                Console.WriteLine(":" + ex.StackTrace);
                throw;
            }
        }
Esempio n. 3
0
 /// <summary>キー付きハッシュ</summary>
 private void btnGetKeyedHash_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(txtKHSSalt.Text))
     {
         // ソルト無し
         if (this.rbnKHSString.Checked)
         {
             // String
             this.txtKHSCode.Text =
                 GetKeyedHash.GetKeyedHashString(
                     this.txtKHSString.Text,
                     (EnumKeyedHashAlgorithm)cbxKHSPV.SelectedValue,
                     this.txtKHSPassword.Text);
         }
         else
         {
             // Bytes
             this.txtKHSCode.Text =
                 CustomEncode.ToHexString(
                     GetKeyedHash.GetKeyedHashBytes(
                         CustomEncode.StringToByte(txtKHSString.Text, CustomEncode.UTF_8),
                         (EnumKeyedHashAlgorithm)cbxKHSPV.SelectedValue,
                         this.txtKHSPassword.Text));
         }
     }
     else
     {
         // ソルト有り
         if (this.nudKHSStretching.Value == 0)
         {
             // ストレッチング無し
             if (this.rbnKHSString.Checked)
             {
                 // String
                 this.txtKHSCode.Text =
                     GetKeyedHash.GetKeyedHashString(
                         this.txtKHSString.Text,
                         (EnumKeyedHashAlgorithm)cbxKHSPV.SelectedValue,
                         this.txtKHSPassword.Text,
                         CustomEncode.StringToByte(this.txtKHSPassword.Text, CustomEncode.UTF_8));
             }
             else
             {
                 // Bytes
                 this.txtKHSCode.Text =
                     CustomEncode.ToHexString(
                         GetKeyedHash.GetKeyedHashBytes(
                             CustomEncode.StringToByte(txtKHSString.Text, CustomEncode.UTF_8),
                             (EnumKeyedHashAlgorithm)cbxKHSPV.SelectedValue,
                             this.txtKHSPassword.Text,
                             CustomEncode.StringToByte(this.txtKHSPassword.Text, CustomEncode.UTF_8)));
             }
         }
         else
         {
             // ストレッチング有り
             if (this.rbnKHSString.Checked)
             {
                 // String
                 this.txtKHSCode.Text =
                     GetKeyedHash.GetKeyedHashString(
                         this.txtKHSString.Text,
                         (EnumKeyedHashAlgorithm)cbxKHSPV.SelectedValue,
                         this.txtKHSPassword.Text,
                         CustomEncode.StringToByte(this.txtKHSPassword.Text, CustomEncode.UTF_8),
                         (int)nudKHSStretching.Value);
             }
             else
             {
                 // Bytes
                 this.txtKHSCode.Text =
                     CustomEncode.ToHexString(
                         GetKeyedHash.GetKeyedHashBytes(
                             CustomEncode.StringToByte(txtKHSString.Text, CustomEncode.UTF_8),
                             (EnumKeyedHashAlgorithm)cbxKHSPV.SelectedValue,
                             this.txtKHSPassword.Text,
                             CustomEncode.StringToByte(this.txtKHSPassword.Text, CustomEncode.UTF_8),
                             (int)nudKHSStretching.Value));
             }
         }
     }
 }