mirror of
https://github.com/azaion/admin.git
synced 2026-04-22 06:56:32 +00:00
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:
@@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" Version="6.12.2" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Azaion.Services\Azaion.Services.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user