mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-06-26 21:13:13 +00:00
naming
This commit is contained in:
32
Esiur.Security.Cryptography/AES.cs
Normal file
32
Esiur.Security.Cryptography/AES.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
49
Esiur.Security.Cryptography/ECDH.cs
Normal file
49
Esiur.Security.Cryptography/ECDH.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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>
|
Reference in New Issue
Block a user