Skip to content

Commit d10a99e

Browse files
authored
Merge pull request #6 from Structum/dev
ComputeHash string representation change.
2 parents f22df7a + 22f551e commit d10a99e

4 files changed

Lines changed: 16 additions & 11 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ Elements is a set of reusable components commonly used in applications.
66

77
| Package | description | nuget Stable |
88
| ------- | ------------ | -------------|
9-
| [Structum.Elements](https://www.nuget.org/packages/Structum.Elements/) | Common classes and Type extensions | [![nuget](https://img.shields.io/badge/nuget-v1.2.0.5-blue.svg)](https://www.nuget.org/packages/Structum.Elements) |
10-
| [Structum.Elements.Web](https://www.nuget.org/packages/Structum.Elements.Web/) | Lightweight Rest Requests and URL parser. | [![nuget](https://img.shields.io/badge/nuget-v1.2.0.5-blue.svg)](https://www.nuget.org/packages/Structum.Elements.Web) |
11-
| [Structum.Elements.Security](https://www.nuget.org/packages/Structum.Elements.Security/) | Common Encryption, Hashing and Password protection classes. | [![nuget](https://img.shields.io/badge/nuget-v1.2.0.5-blue.svg)](https://www.nuget.org/packages/Structum.Elements.Security) |
12-
| [Structum.Elements.Data](https://www.nuget.org/packages/Structum.Elements.Data/) | Data Structures and Hash Functions. | [![nuget](https://img.shields.io/badge/nuget-v1.2.0.5-blue.svg)](https://www.nuget.org/packages/Structum.Elements.Data) |
9+
| [Structum.Elements](https://www.nuget.org/packages/Structum.Elements/) | Common classes and Type extensions | [![nuget](https://img.shields.io/badge/nuget-v1.2.1.0-blue.svg)](https://www.nuget.org/packages/Structum.Elements) |
10+
| [Structum.Elements.Web](https://www.nuget.org/packages/Structum.Elements.Web/) | Lightweight Rest Requests and URL parser. | [![nuget](https://img.shields.io/badge/nuget-v1.2.1.0-blue.svg)](https://www.nuget.org/packages/Structum.Elements.Web) |
11+
| [Structum.Elements.Security](https://www.nuget.org/packages/Structum.Elements.Security/) | Common Encryption, Hashing and Password protection classes. | [![nuget](https://img.shields.io/badge/nuget-v1.2.1.0-blue.svg)](https://www.nuget.org/packages/Structum.Elements.Security) |
12+
| [Structum.Elements.Data](https://www.nuget.org/packages/Structum.Elements.Data/) | Data Structures and Hash Functions. | [![nuget](https://img.shields.io/badge/nuget-v1.2.1.0-blue.svg)](https://www.nuget.org/packages/Structum.Elements.Data) |
1313

1414
## Getting Started
1515

src/Elements.Security/Encryption/Hasher.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ public string ComputeHash(string plainText)
5555

5656
hashBytes = hasher.ComputeHash(hashBytes);
5757

58-
return Convert.ToBase64String(hashBytes);
58+
StringBuilder result = new StringBuilder(hashBytes.Length*2);
59+
foreach(var b in hashBytes) {
60+
result.Append(b.ToString("x2"));
61+
}
62+
63+
return result.ToString();
5964
}
6065
}
6166

tests/Elements.Security.Tests/Encryption/HasherTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public void DefaultComputeHashTest()
1616
{
1717
var hasher = new Hasher();
1818
string hash = hasher.ComputeHash("MyC0013ncrypti0nP@$$w0rd!");
19-
Assert.Equal(44, hash.Length);
19+
Assert.Equal(64, hash.Length);
2020
}
2121

2222
/// <summary>
@@ -29,7 +29,7 @@ public void Md5ComputeHashTest()
2929
HashingAlgorithm = CryptographicHashAlgorithmType.Md5
3030
};
3131
string hash = hasher.ComputeHash("MyC0013ncrypti0nP@$$w0rd!");
32-
Assert.Equal(24, hash.Length);
32+
Assert.Equal(32, hash.Length);
3333
}
3434

3535
/// <summary>
@@ -42,7 +42,7 @@ public void Sha1ComputeHashTest()
4242
HashingAlgorithm = CryptographicHashAlgorithmType.Sha1
4343
};
4444
string hash = hasher.ComputeHash("MyC0013ncrypti0nP@$$w0rd!");
45-
Assert.Equal(28, hash.Length);
45+
Assert.Equal(40, hash.Length);
4646
}
4747

4848
/// <summary>
@@ -55,7 +55,7 @@ public void Sha256ComputeHashTest()
5555
HashingAlgorithm = CryptographicHashAlgorithmType.Sha256
5656
};
5757
string hash = hasher.ComputeHash("MyC0013ncrypti0nP@$$w0rd!");
58-
Assert.Equal(44, hash.Length);
58+
Assert.Equal(64, hash.Length);
5959
}
6060
}
6161
}

tests/Elements.Security.Tests/Passwords/PasswordProtectorTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public void RandomProtectAndCompareTest()
2121

2222
Assert.NotNull(protectedPassword.Password);
2323

24-
Assert.True(protectedPassword.Password.Length <= 44); // The Size of SHA-256
25-
Assert.True(protectedPassword.Password.Length >= 24); // The Size of MD5
24+
Assert.True(protectedPassword.Password.Length <= 64); // The Size of SHA-256
25+
Assert.True(protectedPassword.Password.Length >= 32); // The Size of MD5
2626

2727
Assert.NotNull(protectedPassword.Salt);
2828
Assert.True(protectedPassword.IterationCount > 0);

0 commit comments

Comments
 (0)