using System.Linq; using System.Text; using NUnit.Framework; using ShareeBike.Services.BluetoothLock.Crypto; namespace SharedBusinessLogic.Tests.Fixtures.ObjectTests.Services.BluetoothLock.Crypto { [TestFixture] public class TestCryptoHelper { /// /// Ensures that decryption from haveltec- lib produces the same results than sharee lib. /// [Test] public void Test_DecryptStringFromBytes_Aes() { // keyCopri (value copied from debugging session of sharing_ble_lib/ haveltec code) var keyCopri = (new sbyte[] { -6, 53, 29, -112, 7, -83, -41, -7, 30, 45, -13, -2, -108, -29, -90, 71, 15, -74, -76, 32, 0, 0, 0, 0 }).Select(x => (byte)x).ToArray(); // Encrypted seed value from lock (value copied from debugging session of sharing_ble_lib/ haveltec code) var seedLockEnc = (new sbyte[] { 50, 51, -40, 64, 42, 82, 97, -24, 20, -39, -15, 126, 119, -110, 47, -18 }).Select(x => (byte)x).ToArray(); // Decrypted seed value from lock (value copied from debugging session of sharing_ble_lib/ haveltec code) var acces_key = (new sbyte[] { 19, -66, 55, 18, -106, -92, 70, -40, 117, -87, -19, 124, 19, 54, -18, -82 }).Select(x => (byte)x).ToArray(); var decrypt = new Cipher().Decrypt(keyCopri, seedLockEnc); Assert.That(acces_key.SequenceEqual(decrypt), Is.True); } [Test] public void TestGetSeedLock() { // seed copri (value copied from debugging session of sharing_ble_lib/ haveltec code) byte[] seedCopri = (new sbyte[] { -7, -69, 16, -52, 88, 38, -92, 82, -99, -79, 19, 16, -41, -127, 51, 24 }).Select(x => (byte)x).ToArray(); // keyCopri (value copied from debugging session of sharing_ble_lib/ haveltec code) byte[] keyCopri = (new sbyte[] { -6, 53, 29, -112, 7, -83, -41, -7, 30, 45, -13, -2, -108, -29, -90, 71, 15, -74, -76, 32, 0, 0, 0, 0 }).Select(x => (byte)x).ToArray(); // Encrypted seed value from lock (value copied from debugging session of sharing_ble_lib/ haveltec code) byte[] seedLockEnc = (new sbyte[] { 92, 80, -36, -2, 101, -31, -23, -43, 71, 62, 126, -70, 54, -53, -119, -56 }).Select(x => (byte)x).ToArray(); //// Decrypted seed value? access values? from lock (value copied from debugging session of sharing_ble_lib/ haveltec code) byte[] seedLockDec = (new sbyte[] { 62, -51, 96, -80, 7, -84, 48, -104, 47, 51, -22, -23, 30, -10, -88, -97 }).Select(x => (byte)x).ToArray(); var crypto = new AuthCryptoHelper( seedLockEnc, keyCopri, null); var result = crypto.GetSeedLock(); Assert.That(seedLockDec.SequenceEqual(result), Is.True); } [Test] public void TestGetAccessKeyEncrypted() { // seed copri (value copied from debugging session of sharing_ble_lib/ haveltec code) byte[] seedCopri = (new sbyte[] { -7, -69, 16, -52, 88, 38, -92, 82, -99, -79, 19, 16, -41, -127, 51, 24 }).Select(x => (byte)x).ToArray(); // keyCopri (value copied from debugging session of sharing_ble_lib/ haveltec code) byte[] keyCopri = (new sbyte[] { -6, 53, 29, -112, 7, -83, -41, -7, 30, 45, -13, -2, -108, -29, -90, 71, 15, -74, -76, 32, 0, 0, 0, 0 }).Select(x => (byte)x).ToArray(); // Encrypted seed value from lock (value copied from debugging session of sharing_ble_lib/ haveltec code) byte[] seedLockEnc = (new sbyte[] { 92, 80, -36, -2, 101, -31, -23, -43, 71, 62, 126, -70, 54, -53, -119, -56 }).Select(x => (byte)x).ToArray(); // Decrypted seed value? access values? from lock (value copied from debugging session of sharing_ble_lib/ haveltec code) byte[] seedLockDec = (new sbyte[] { 62, -51, 96, -80, 7, -84, 48, -104, 47, 51, -22, -23, 30, -10, -88, -97 }).Select(x => (byte)x).ToArray(); var crypto = new AuthCryptoHelper( seedLockEnc, keyCopri, null); var result = crypto.GetSeedLock(); Assert.That( Encoding.UTF8.GetString(result), Is.EqualTo(Encoding.UTF8.GetString(seedLockDec))); } } }