public void NullParameterTest() { var keyPair = new KeyPair(new PrivateSecretKey(K_PRI_ALICE), new PublicKey(K_PUB_ALICE)); Assert.ThrowsException <ArgumentNullException>(() => new SharedLocker(null, null)); Assert.ThrowsException <ArgumentNullException>(() => new SharedLocker(keyPair.Public, null)); Assert.ThrowsException <ArgumentNullException>(() => new SharedLocker(null, keyPair.Secret)); var sharedLocker = new SharedLocker(keyPair.Public, keyPair.Secret); Assert.ThrowsException <ArgumentNullException>(() => sharedLocker.Lock(str: null)); Assert.ThrowsException <ArgumentNullException>(() => sharedLocker.Lock(str: "")); Assert.ThrowsException <ArgumentNullException>(() => sharedLocker.Lock(data: null)); Assert.ThrowsException <ArgumentNullException>(() => sharedLocker.Lock(data: new byte[0])); }
public void RoundTripTest_WrongKeys() { var AliceKeys = new KeyPair(new PrivateSecretKey(K_PRI_ALICE), new PublicKey(K_PUB_ALICE)); var BobKeys = new KeyPair(new PrivateSecretKey(K_PRI_BOB), new PublicKey(K_PUB_BOB)); var locker = new SharedLocker(BobKeys.Public, AliceKeys.Secret); var locked = locker.Lock(MESSAGE); //Try to decrypt with alice key Assert.ThrowsException <CryptographicException>(() => locked.UnlockString(AliceKeys.Public, AliceKeys.Secret)); }
public void RoundTripTest() { var AliceKeys = new KeyPair(new PrivateSecretKey(K_PRI_ALICE), new PublicKey(K_PUB_ALICE)); var BobKeys = new KeyPair(new PrivateSecretKey(K_PRI_BOB), new PublicKey(K_PUB_BOB)); var locker = new SharedLocker(BobKeys.Public, AliceKeys.Secret); var locked = locker.Lock(MESSAGE); var unlocked = locked.UnlockString(AliceKeys.Public, BobKeys.Secret); Assert.AreEqual(MESSAGE, unlocked); }
public void RoundTripTest_Tampered() { var AliceKeys = new KeyPair(new PrivateSecretKey(K_PRI_ALICE), new PublicKey(K_PUB_ALICE)); var BobKeys = new KeyPair(new PrivateSecretKey(K_PRI_BOB), new PublicKey(K_PUB_BOB)); var locker = new SharedLocker(BobKeys.Public, AliceKeys.Secret); var locked = locker.Lock(MESSAGE); for (int i = 0; i < 5; i++) { locked.Cipher[i] = 0; } Assert.ThrowsException <CryptographicException>(() => locked.UnlockString(AliceKeys.Public, BobKeys.Secret)); }