finished session encrypt test
This commit is contained in:
parent
abe1452200
commit
915653b035
@ -5,6 +5,7 @@ using System.Text;
|
||||
using chestcrypto.session;
|
||||
using chestcrypto.session.crypto;
|
||||
using chestcrypto.exceptions;
|
||||
using chestcrypto;
|
||||
using Sodium;
|
||||
|
||||
namespace sessionTestEncrypt
|
||||
@ -20,16 +21,20 @@ namespace sessionTestEncrypt
|
||||
|
||||
[Test]
|
||||
public void TestEncrypt(){
|
||||
byte[] publicK = PublicKeyBox.GenerateKeyPair().PublicKey;
|
||||
byte[] privateK = PublicKeyBox.GenerateKeyPair().PrivateKey;
|
||||
byte[] newK = PublicKeyBox.GenerateKeyPair().PublicKey;
|
||||
var pair1 = PublicKeyBox.GenerateKeyPair();
|
||||
byte[] publicK = pair1.PublicKey;
|
||||
byte[] privateK = pair1.PrivateKey;
|
||||
var pair = PublicKeyBox.GenerateKeyPair();
|
||||
byte[] privKey = pair.PrivateKey;
|
||||
byte[] pubKey = pair.PublicKey;
|
||||
byte[] message = UTF8Encoding.UTF8.GetBytes("Hello friend");
|
||||
Session session = new Session(privateK, publicK, true, 5);
|
||||
session.setMinimumKeyExpireSeconds(1);
|
||||
session.setMessageDelay((long) 1);
|
||||
session.addPublic(newK, getFutureTime(9));
|
||||
session.generatePrivate();
|
||||
session.setMinimumKeyExpireSeconds(10);
|
||||
session.setMessageDelay((long) 25);
|
||||
session.addPublic(pubKey, getFutureTime(100));
|
||||
byte[] encrypted = SessionCrypto.encrypt(session, message);
|
||||
byte[] decrypted = Curve25519.decrypt(privKey, publicK, encrypted);
|
||||
Assert.AreEqual(decrypted, message);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace chestcrypto.session.crypto{
|
||||
|
||||
public static byte[] encrypt(Session activeSession, byte[] message){
|
||||
byte[] publicKey = activeSession.getLatestPublicKey();
|
||||
byte[] privateKey = activeSession.getLatestPrivateKey();
|
||||
byte[] privateKey = activeSession.getOurMasterPrivate();
|
||||
return Curve25519.encrypt(privateKey, publicKey, message);
|
||||
}
|
||||
|
||||
|
@ -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 setMessageDelay(long newDelay){
|
||||
messageDelay = newDelay;
|
||||
|
Loading…
Reference in New Issue
Block a user