mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.4 KiB
47 lines
1.4 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
|
|
namespace TestSuite.Utils
|
|
{
|
|
public static class RandomHash
|
|
{
|
|
public static string New()
|
|
{
|
|
return Guid.NewGuid()
|
|
.ToString().Sha256Base64()
|
|
.ToLowerInvariant()
|
|
.Replace("+", "x", StringComparison.Ordinal)
|
|
.Replace("=", "x", StringComparison.Ordinal)
|
|
.Replace("/", "x", StringComparison.Ordinal);
|
|
}
|
|
|
|
public static string Simple()
|
|
{
|
|
return Guid.NewGuid().ToString().Replace("-", string.Empty, StringComparison.Ordinal);
|
|
}
|
|
|
|
public static string Sha256Base64(this string value)
|
|
{
|
|
return Sha256Base64(Encoding.UTF8.GetBytes(value));
|
|
}
|
|
|
|
public static string Sha256Base64(this byte[] bytes)
|
|
{
|
|
using (var sha = SHA256.Create())
|
|
{
|
|
var bytesHash = sha.ComputeHash(bytes);
|
|
|
|
var result = Convert.ToBase64String(bytesHash);
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|