2021-09-27 12:42:46 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
using System.Text;
|
|
|
|
using Wabbajack.Hashing.xxHash64;
|
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
namespace Wabbajack.Common;
|
|
|
|
|
|
|
|
public static class StringExtensions
|
2021-09-27 12:42:46 +00:00
|
|
|
{
|
2021-10-23 16:51:17 +00:00
|
|
|
public static string StringSha256Hex(this string s)
|
2021-09-27 12:42:46 +00:00
|
|
|
{
|
2021-10-23 16:51:17 +00:00
|
|
|
var sha = SHA256.Create();
|
|
|
|
using (var o = new CryptoStream(Stream.Null, sha, CryptoStreamMode.Write))
|
2021-09-27 12:42:46 +00:00
|
|
|
{
|
2021-10-23 16:51:17 +00:00
|
|
|
using var i = new MemoryStream(Encoding.UTF8.GetBytes(s));
|
|
|
|
i.CopyTo(o);
|
2021-09-27 12:42:46 +00:00
|
|
|
}
|
2021-10-23 16:51:17 +00:00
|
|
|
|
|
|
|
return sha.Hash!.ToHex();
|
2021-09-27 12:42:46 +00:00
|
|
|
}
|
|
|
|
}
|