-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SHA256 hash is calculated from Artist.Name and Album.Name to get deterministic cover file name
- Loading branch information
Showing
8 changed files
with
136 additions
and
89 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
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 was deleted.
Oops, something went wrong.
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
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; | ||
|
||
namespace SynAudio.Utils | ||
{ | ||
public static class Sha256Hash | ||
{ | ||
/// <summary> | ||
/// Computes SHA256 hash from object using System.Text.Json.JsonSerializer. | ||
/// </summary> | ||
/// <param name="o">The object to compute the hash from.</param> | ||
/// <returns>64 characters</returns> | ||
public static string FromObject(object o) | ||
{ | ||
byte[] serialized = System.Text.Json.JsonSerializer.SerializeToUtf8Bytes(o); | ||
using (var hash = System.Security.Cryptography.SHA256.Create()) | ||
return BitConverter.ToString(hash.ComputeHash(serialized)).Replace("-", string.Empty); | ||
} | ||
|
||
/// <summary> | ||
/// Computes SHA256 hash from byte array. | ||
/// </summary> | ||
/// <param name="bytes">The bytes to compute the hash from.</param> | ||
/// <returns>64 characters</returns> | ||
public static string FromByteArray(byte[] bytes) | ||
{ | ||
using (var hash = System.Security.Cryptography.SHA256.Create()) | ||
return BitConverter.ToString(hash.ComputeHash(bytes)).Replace("-", string.Empty); | ||
} | ||
} | ||
} |