diff --git a/tests/doublekeyTest.cs b/tests/doublekeyTest.cs new file mode 100644 index 0000000..62e5f77 --- /dev/null +++ b/tests/doublekeyTest.cs @@ -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(); + } + } + } + } +} \ No newline at end of file diff --git a/treasurechest/chestcrypto/doublekey/exceptions.cs b/treasurechest/chestcrypto/doublekey/exceptions.cs new file mode 100644 index 0000000..40a6e44 --- /dev/null +++ b/treasurechest/chestcrypto/doublekey/exceptions.cs @@ -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) + { + } + } + +} \ No newline at end of file diff --git a/treasurechest/chestcrypto/doublekey/private.cs b/treasurechest/chestcrypto/doublekey/private.cs new file mode 100644 index 0000000..b964ad3 --- /dev/null +++ b/treasurechest/chestcrypto/doublekey/private.cs @@ -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; + } + + } + +} \ No newline at end of file diff --git a/treasurechest/chestcrypto/doublekey/public.cs b/treasurechest/chestcrypto/doublekey/public.cs new file mode 100644 index 0000000..97b6a42 --- /dev/null +++ b/treasurechest/chestcrypto/doublekey/public.cs @@ -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]; + } + } + + } + +} \ No newline at end of file diff --git a/treasurechest/chestcrypto/keygen.cs b/treasurechest/chestcrypto/keygen.cs index 5c644dc..041d835 100644 --- a/treasurechest/chestcrypto/keygen.cs +++ b/treasurechest/chestcrypto/keygen.cs @@ -1,5 +1,4 @@ using Sodium; -using System.Security.Cryptography; using System; diff --git a/treasurechest/keyring/keyring.cs b/treasurechest/keyring/keyring.cs new file mode 100644 index 0000000..7c7f1d4 --- /dev/null +++ b/treasurechest/keyring/keyring.cs @@ -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){ + + } + } + +} \ No newline at end of file