added double key files with DoublePublicKey implementation
This commit is contained in:
parent
d25e94816e
commit
7b789a0910
44
tests/doublekeyTest.cs
Normal file
44
tests/doublekeyTest.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
22
treasurechest/chestcrypto/doublekey/exceptions.cs
Normal file
22
treasurechest/chestcrypto/doublekey/exceptions.cs
Normal 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)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
16
treasurechest/chestcrypto/doublekey/private.cs
Normal file
16
treasurechest/chestcrypto/doublekey/private.cs
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
36
treasurechest/chestcrypto/doublekey/public.cs
Normal file
36
treasurechest/chestcrypto/doublekey/public.cs
Normal 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];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
using Sodium;
|
||||
using System.Security.Cryptography;
|
||||
using System;
|
||||
|
||||
|
||||
|
21
treasurechest/keyring/keyring.cs
Normal file
21
treasurechest/keyring/keyring.cs
Normal 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){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user