finished session encrypt test

This commit is contained in:
Kevin Froman 2020-05-30 18:44:02 -05:00
parent abe1452200
commit 915653b035
3 changed files with 16 additions and 8 deletions

View File

@ -5,6 +5,7 @@ using System.Text;
using chestcrypto.session; using chestcrypto.session;
using chestcrypto.session.crypto; using chestcrypto.session.crypto;
using chestcrypto.exceptions; using chestcrypto.exceptions;
using chestcrypto;
using Sodium; using Sodium;
namespace sessionTestEncrypt namespace sessionTestEncrypt
@ -20,16 +21,20 @@ namespace sessionTestEncrypt
[Test] [Test]
public void TestEncrypt(){ public void TestEncrypt(){
byte[] publicK = PublicKeyBox.GenerateKeyPair().PublicKey; var pair1 = PublicKeyBox.GenerateKeyPair();
byte[] privateK = PublicKeyBox.GenerateKeyPair().PrivateKey; byte[] publicK = pair1.PublicKey;
byte[] newK = PublicKeyBox.GenerateKeyPair().PublicKey; byte[] privateK = pair1.PrivateKey;
var pair = PublicKeyBox.GenerateKeyPair();
byte[] privKey = pair.PrivateKey;
byte[] pubKey = pair.PublicKey;
byte[] message = UTF8Encoding.UTF8.GetBytes("Hello friend"); byte[] message = UTF8Encoding.UTF8.GetBytes("Hello friend");
Session session = new Session(privateK, publicK, true, 5); Session session = new Session(privateK, publicK, true, 5);
session.setMinimumKeyExpireSeconds(1); session.setMinimumKeyExpireSeconds(10);
session.setMessageDelay((long) 1); session.setMessageDelay((long) 25);
session.addPublic(newK, getFutureTime(9)); session.addPublic(pubKey, getFutureTime(100));
session.generatePrivate();
byte[] encrypted = SessionCrypto.encrypt(session, message); byte[] encrypted = SessionCrypto.encrypt(session, message);
byte[] decrypted = Curve25519.decrypt(privKey, publicK, encrypted);
Assert.AreEqual(decrypted, message);
} }
} }

View File

@ -9,7 +9,7 @@ namespace chestcrypto.session.crypto{
public static byte[] encrypt(Session activeSession, byte[] message){ public static byte[] encrypt(Session activeSession, byte[] message){
byte[] publicKey = activeSession.getLatestPublicKey(); byte[] publicKey = activeSession.getLatestPublicKey();
byte[] privateKey = activeSession.getLatestPrivateKey(); byte[] privateKey = activeSession.getOurMasterPrivate();
return Curve25519.encrypt(privateKey, publicKey, message); return Curve25519.encrypt(privateKey, publicKey, message);
} }

View File

@ -69,6 +69,9 @@ namespace chestcrypto{
} }
public byte[] getOurMasterPrivate(){return ourMasterPrivateKey;}
public byte[] getTheirMasterPublic(){return theirMasterPublicKey;}
public void setMinimumKeyExpireSeconds(int newSeconds){minimumKeyExpireSeconds = newSeconds;} public void setMinimumKeyExpireSeconds(int newSeconds){minimumKeyExpireSeconds = newSeconds;}
public void setMessageDelay(long newDelay){ public void setMessageDelay(long newDelay){
messageDelay = newDelay; messageDelay = newDelay;