mirror of
https://github.com/azaion/admin.git
synced 2026-04-22 08:16:34 +00:00
121052a3ef
add security encryption and hashing: WIP add endpoints: register user, get and save resources add db main operations, User entity
41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
using System.Text;
|
|
using Azaion.Services;
|
|
using FluentAssertions;
|
|
using Xunit;
|
|
|
|
namespace Azaion.Test;
|
|
|
|
public class SecurityTest
|
|
{
|
|
[Fact]
|
|
public async Task EncryptDecryptTest()
|
|
{
|
|
var testString = "Hello World Test dfvjkhsdbfvkljh sabdljsdafv asdv";
|
|
var username = "user@azaion.com";
|
|
var password = "testpw";
|
|
var key = Security.MakeEncryptionKey(username, password);
|
|
|
|
await using var encryptedStream = new MemoryStream();
|
|
await StringToStream(testString).Encrypt(encryptedStream, key);
|
|
|
|
await using var decryptedStream = new MemoryStream();
|
|
await encryptedStream.Decrypt(decryptedStream, key);
|
|
|
|
var str = StreamToString(decryptedStream);
|
|
str.Should().Be(testString);
|
|
}
|
|
|
|
private static string StreamToString(Stream stream)
|
|
{
|
|
stream.Position = 0;
|
|
using var reader = new StreamReader(stream, Encoding.UTF8);
|
|
return reader.ReadToEnd();
|
|
}
|
|
|
|
private static Stream StringToStream(string src)
|
|
{
|
|
var byteArray = Encoding.UTF8.GetBytes(src);
|
|
return new MemoryStream(byteArray);
|
|
}
|
|
|
|
} |