added double key files with DoublePublicKey implementation

This commit is contained in:
Kevin Froman 2020-05-11 02:08:46 -05:00
parent d25e94816e
commit 7b789a0910
6 changed files with 139 additions and 1 deletions

44
tests/doublekeyTest.cs Normal file
View File

@ -0,0 +1,44 @@
using NUnit.Framework;
using chestcrypto;
using System;
using Sodium;
namespace DoubleKeyTests
{
public class Tests
{
[SetUp]
public void Setup()
{
}
[Test]
public void TestDoublePublicKey()
{
// Test that the combined key loader loads both constructors with the same results
byte[] signingKey = PublicKeyAuth.GenerateKeyPair().PublicKey;
byte[] encryptionKey = PublicKeyBox.GenerateKeyPair().PublicKey;
byte[] combinedKey = new byte[signingKey.Length + encryptionKey.Length];
Buffer.BlockCopy(signingKey, 0, combinedKey, 0, signingKey.Length);
Buffer.BlockCopy(encryptionKey, 0, combinedKey, signingKey.Length, encryptionKey.Length);
DoublePublicKey combinedLoad = new chestcrypto.DoublePublicKey(combinedKey);
DoublePublicKey parameterLoad = new chestcrypto.DoublePublicKey(signingKey, encryptionKey);
if (combinedLoad.getRawDouble().Length != parameterLoad.getRawDouble().Length){
Assert.Fail();
}
if (combinedLoad.getRawDouble().Length != 64){
Assert.Fail();
}
for (int i = 0; i < combinedLoad.getRawDouble().Length; i++){
if (combinedLoad.getRawDouble()[i] != parameterLoad.getRawDouble()[i]){
Assert.Fail();
}
if (combinedLoad.getRawDouble()[i] != combinedKey[i]){
Assert.Fail();
}
}
}
}
}

View File

@ -0,0 +1,22 @@
using System;
namespace chestcrypto {
public class InvalidDoubleKeyException : Exception
{
public InvalidDoubleKeyException()
{
}
public InvalidDoubleKeyException(string message)
: base(message)
{
}
public InvalidDoubleKeyException(string message, Exception inner)
: base(message, inner)
{
}
}
}

View File

@ -0,0 +1,16 @@
namespace chestcrypto{
public class DoublePrivateKey{
private byte[] signingprivateKey;
public byte[] encryptprivateKey;
public DoublePrivateKey(byte[] sign, byte[] encrypt){
signingprivateKey = sign;
encryptprivateKey = encrypt;
}
}
}

View File

@ -0,0 +1,36 @@
namespace chestcrypto{
public class DoublePublicKey{
private byte[] signingPublicKey = new byte[32];
private byte[] encryptPublicKey = new byte[32];
private string[] signingPublicKeyString;
private string[] encryptPublicKeyString;
public byte[] getRawDouble(){
return ByteCombiner.Combine(signingPublicKey, encryptPublicKey);
}
public DoublePublicKey(byte[] sign, byte[] encrypt){
signingPublicKey = sign;
encryptPublicKey = encrypt;
}
public DoublePublicKey(byte[] joinedKey){
if (joinedKey.Length != 64){
throw new InvalidDoubleKeyException();
}
for (int i = 0; i < joinedKey.Length; i++){
if (i < 32){
this.signingPublicKey[i] = joinedKey[i];
continue;
}
this.encryptPublicKey[i - 32] = joinedKey[i];
}
}
}
}

View File

@ -1,5 +1,4 @@
using Sodium; using Sodium;
using System.Security.Cryptography;
using System; using System;

View File

@ -0,0 +1,21 @@
using chestcrypto;
namespace keyring{
public class KeyRing
{
private string storageFile = null;
public KeyRing(string storageFile){
}
public void addPublicKey(DoublePublicKey key){
}
public void deleteKey(DoublePrivateKey key){
}
}
}