-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
使用 System.IO.Hashing 库
- Loading branch information
Showing
6 changed files
with
75 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
DotVast.HashTool.WinUI/Helpers/Hashes/NonCryptographicHashAlgorithmAdapter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.IO.Hashing; | ||
using System.Security.Cryptography; | ||
|
||
namespace DotVast.HashTool.WinUI.Helpers.Hashes; | ||
|
||
internal static class NonCryptographicHashAlgorithmAdapterExtensions | ||
{ | ||
public static HashAlgorithm ToHashAlgorithm(this NonCryptographicHashAlgorithm hash) => | ||
new NonCryptographicHashAlgorithmAdapter(hash); | ||
} | ||
|
||
sealed file class NonCryptographicHashAlgorithmAdapter : HashAlgorithm | ||
{ | ||
private readonly NonCryptographicHashAlgorithm _hash; | ||
|
||
public NonCryptographicHashAlgorithmAdapter(NonCryptographicHashAlgorithm hash) | ||
{ | ||
_hash = hash; | ||
HashSizeValue = hash.HashLengthInBytes * 8; | ||
} | ||
|
||
public override void Initialize() => | ||
_hash.Reset(); | ||
|
||
protected override void HashCore(byte[] array, int ibStart, int cbSize) => | ||
_hash.Append(array.AsSpan(ibStart, cbSize)); | ||
|
||
protected override byte[] HashFinal() => | ||
_hash.GetCurrentHash(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters