public void GetKeyedHashBytesTest(byte[] asb, EnumKeyedHashAlgorithm eha, string password) { try { // anyWarp 棟梁の部品を使用してハッシュ値を取得 byte[] hashBytes = GetKeyedHash.GetKeyedHashBytes(asb, eha, password); // anyWarp 棟梁の部品を使用して、もう一度ハッシュ値を取得 byte[] hashBytes2 = GetKeyedHash.GetKeyedHashBytes(asb, eha, password); // ハッシュ値が同じかどうかをチェック Assert.AreNotEqual(asb, hashBytes); Assert.AreNotEqual(asb, hashBytes2); Assert.AreEqual(hashBytes, hashBytes2); } catch (Exception ex) { // Print a stack trace when an exception occurs. Console.WriteLine(ex.StackTrace); throw; } }
/// <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)); } } } }