Init commit

add security encryption and hashing: WIP
add endpoints: register user, get and save resources
add db main operations, User entity
This commit is contained in:
Alex Bezdieniezhnykh
2024-11-09 00:37:43 +02:00
commit 121052a3ef
26 changed files with 605 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
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);
}
}