treasurechest/tests/session/testSessionEncrypt.cs

36 lines
1.1 KiB
C#
Raw Normal View History

2020-05-30 08:06:08 +00:00
using NUnit.Framework;
using System;
using System.Linq;
2020-05-30 23:00:49 +00:00
using System.Text;
2020-05-30 08:06:08 +00:00
using chestcrypto.session;
2020-05-30 23:00:49 +00:00
using chestcrypto.session.crypto;
2020-05-30 08:06:08 +00:00
using chestcrypto.exceptions;
using Sodium;
namespace sessionTestEncrypt
{
public class Tests
{
[SetUp]
public void Setup()
{
}
public long getFutureTime(int seconds){return DateTimeOffset.UtcNow.ToUnixTimeSeconds() + (long) seconds;}
[Test]
public void TestEncrypt(){
byte[] publicK = PublicKeyBox.GenerateKeyPair().PublicKey;
byte[] privateK = PublicKeyBox.GenerateKeyPair().PrivateKey;
byte[] newK = PublicKeyBox.GenerateKeyPair().PublicKey;
2020-05-30 23:00:49 +00:00
byte[] message = UTF8Encoding.UTF8.GetBytes("Hello friend");
2020-05-30 08:06:08 +00:00
Session session = new Session(privateK, publicK, true, 5);
session.setMinimumKeyExpireSeconds(1);
session.setMessageDelay((long) 1);
session.addPublic(newK, getFutureTime(9));
2020-05-30 23:00:49 +00:00
session.generatePrivate();
byte[] encrypted = SessionCrypto.encrypt(session, message);
2020-05-30 08:06:08 +00:00
}
}
}