2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-06-26 21:13:13 +00:00
This commit is contained in:
2024-03-26 20:34:00 +03:00
parent 8ab0e811bd
commit 5105179b25
4 changed files with 1 additions and 1 deletions

View File

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
namespace Esiur.Security.Cryptography
{
public class AES : ISymetricCipher
{
Aes aes = Aes.Create();
public ushort Identifier => 1;
public byte[] Decrypt(byte[] data)
{
throw new NotImplementedException();
}
public byte[] Encrypt(byte[] data)
{
throw new NotImplementedException();
}
public byte[] SetKey(byte[] key)
{
//aes.Key = key;
//aes.IV = key;
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
using Esiur.Security.Cryptography;
using Esiur.Data;
using System.Linq;
namespace Esiur.Security.Cryptography
{
public class ECDH : IKeyExchanger
{
public ushort Identifier => 1;
ECDiffieHellman ecdh = ECDiffieHellman.Create(ECCurve.NamedCurves.brainpoolP256r1);
public byte[] ComputeSharedKey(byte[] key)
{
var x = key.Clip(0, (uint)key.Length / 2);
var y = key.Clip((uint)key.Length / 2, (uint)key.Length / 2);
ECParameters parameters = new ECParameters
{
Curve = ECCurve.NamedCurves.brainpoolP256r1,
Q = {
X = x,
Y = y,
}
};
byte[] derivedKey;
using (ECDiffieHellman peer = ECDiffieHellman.Create(parameters))
using (ECDiffieHellmanPublicKey peerPublic = peer.PublicKey)
{
return derivedKey = ecdh.DeriveKeyMaterial(peerPublic);
}
}
public byte[] GetPublicKey()
{
var kp = ecdh.PublicKey.ExportParameters();
var key = DC.Combine(kp.Q.X, 0, (uint)kp.Q.X.Length, kp.Q.Y, 0, (uint)kp.Q.Y.Length);
return key;
}
}
}

View File

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Esiur\Esiur.csproj" />
</ItemGroup>
</Project>