|
|
|
@ -16,7 +16,7 @@ namespace Squidex.Infrastructure |
|
|
|
public static string New() |
|
|
|
{ |
|
|
|
return Guid.NewGuid() |
|
|
|
.ToString().Sha256Base64() |
|
|
|
.ToString().ToSha256Base64() |
|
|
|
.ToLowerInvariant() |
|
|
|
.Replace("+", "x") |
|
|
|
.Replace("=", "x") |
|
|
|
@ -28,12 +28,12 @@ namespace Squidex.Infrastructure |
|
|
|
return Guid.NewGuid().ToString().Replace("-", string.Empty); |
|
|
|
} |
|
|
|
|
|
|
|
public static string Sha256Base64(this string value) |
|
|
|
public static string ToSha256Base64(this string value) |
|
|
|
{ |
|
|
|
return Sha256Base64(Encoding.UTF8.GetBytes(value)); |
|
|
|
return ToSha256Base64(Encoding.UTF8.GetBytes(value)); |
|
|
|
} |
|
|
|
|
|
|
|
public static string Sha256Base64(this byte[] bytes) |
|
|
|
public static string ToSha256Base64(this byte[] bytes) |
|
|
|
{ |
|
|
|
using (var sha = SHA256.Create()) |
|
|
|
{ |
|
|
|
@ -44,5 +44,42 @@ namespace Squidex.Infrastructure |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static string ToSha256(this string value) |
|
|
|
{ |
|
|
|
return value.ToHashed(SHA256.Create()); |
|
|
|
} |
|
|
|
|
|
|
|
public static string ToSha256(this byte[] bytes) |
|
|
|
{ |
|
|
|
return bytes.ToHashed(SHA256.Create()); |
|
|
|
} |
|
|
|
|
|
|
|
public static string ToMD5(this string value) |
|
|
|
{ |
|
|
|
return value.ToHashed(MD5.Create()); |
|
|
|
} |
|
|
|
|
|
|
|
public static string ToMD5(this byte[] bytes) |
|
|
|
{ |
|
|
|
return bytes.ToHashed(MD5.Create()); |
|
|
|
} |
|
|
|
|
|
|
|
public static string ToHashed(this string value, HashAlgorithm algorithm) |
|
|
|
{ |
|
|
|
return Encoding.UTF8.GetBytes(value).ToHashed(algorithm); |
|
|
|
} |
|
|
|
|
|
|
|
public static string ToHashed(this byte[] bytes, HashAlgorithm algorithm) |
|
|
|
{ |
|
|
|
using (algorithm) |
|
|
|
{ |
|
|
|
var bytesHash = algorithm.ComputeHash(bytes); |
|
|
|
|
|
|
|
var result = Encoding.UTF8.GetString(bytesHash); |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|