68 lines
2.7 KiB
Plaintext
68 lines
2.7 KiB
Plaintext
|
using NUnit.Framework;
|
||
|
using ServiceShared.Crypto;
|
||
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Security.Cryptography;
|
||
|
using System.Text;
|
||
|
using System.Threading.Tasks;
|
||
|
|
||
|
namespace ServiceOutsideTests.Crypto
|
||
|
{
|
||
|
public class Curve25519
|
||
|
{
|
||
|
[Test]
|
||
|
public void SharedKeys()
|
||
|
{
|
||
|
KeyPair aliceKey = ServiceShared.Crypto.Curve25519.GenerateKeyPair();
|
||
|
KeyPair bobKey = ServiceShared.Crypto.Curve25519.GenerateKeyPair();
|
||
|
byte[] aliceSharedKey = aliceKey.GetSharedKey(bobKey.PublicKey);
|
||
|
byte[] bobSharedKey = bobKey.GetSharedKey(aliceKey.PublicKey);
|
||
|
|
||
|
Assert.AreEqual(aliceSharedKey, bobSharedKey);
|
||
|
}
|
||
|
|
||
|
|
||
|
[Test]
|
||
|
public void AliceSendToBob()
|
||
|
{
|
||
|
KeyPair aliceKey = ServiceShared.Crypto.Curve25519.GenerateKeyPair();
|
||
|
KeyPair bobKey = ServiceShared.Crypto.Curve25519.GenerateKeyPair();
|
||
|
|
||
|
byte[] aliceSharedKey = aliceKey.GetSharedKey(bobKey.PublicKey);
|
||
|
byte[] bobSharedKey = bobKey.GetSharedKey(aliceKey.PublicKey);
|
||
|
|
||
|
string key = "a dasdas djakl jdklas jdlkjakldhsajkdhsakdhkajhdkjgahkdgsagdas gdj sadag jdsaj gdg jasdagj dgsa gdsa dsga dgsja gdjagdgasj gjhdga gdja";
|
||
|
string input = "Hello World";
|
||
|
string encrypted = ServiceShared.Crypto.AES.Encrypt(input, aliceSharedKey);
|
||
|
string decrypted = ServiceShared.Crypto.AES.Decrypt(encrypted, bobSharedKey);
|
||
|
Assert.AreEqual(input, decrypted);
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void BobSendToAlice()
|
||
|
{
|
||
|
KeyPair aliceKey = ServiceShared.Crypto.Curve25519.GenerateKeyPair();
|
||
|
KeyPair bobKey = ServiceShared.Crypto.Curve25519.GenerateKeyPair();
|
||
|
|
||
|
byte[] aliceSharedKey = aliceKey.GetSharedKey(bobKey.PublicKey);
|
||
|
byte[] bobSharedKey = bobKey.GetSharedKey(aliceKey.PublicKey);
|
||
|
|
||
|
string key = "a dasdas djakl jdklas jdlkjakldhsajkdhsakdhkajhdkjgahkdgsagdas gdj sadag jdsaj gdg jasdagj dgsa gdsa dsga dgsja gdjagdgasj gjhdga gdja";
|
||
|
string input = "Hello World";
|
||
|
string encrypted = ServiceShared.Crypto.AES.Encrypt(input, bobSharedKey);
|
||
|
string decrypted = ServiceShared.Crypto.AES.Decrypt(encrypted, aliceSharedKey);
|
||
|
Assert.AreEqual(input, decrypted);
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void BobVerifyAlicasSignature()
|
||
|
{
|
||
|
KeyPair aliceKey = ServiceShared.Crypto.Curve25519.GenerateKeyPair();
|
||
|
KeyPair bobKey = ServiceShared.Crypto.Curve25519.GenerateKeyPair();
|
||
|
string aliceSignature = aliceKey.GetSignature("BefundApp");
|
||
|
Assert.IsTrue(bobKey.VerifySignature("BefundApp", aliceSignature, aliceKey.SigningPublicKey));
|
||
|
}
|
||
|
}
|
||
|
}
|