wabbajack/Wabbajack.Common/StringExtensions.cs

27 lines
705 B
C#
Raw Normal View History

2021-12-27 05:18:52 +00:00
using System;
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
}
2021-12-27 05:18:52 +00:00
public static bool ContainsCaseInsensitive(this string src, string contains)
{
return src.Contains(contains, StringComparison.InvariantCultureIgnoreCase);
}
2021-09-27 12:42:46 +00:00
}