public void WhenByteArrayAndKeyIsNullAndDrecryptThenShouldThrowArgumentNullException() { byte[] data = { 10, 47, 67, 10, 91, 15, 33, 25 }; int keySize = 1024; Assert.ThrowsException <ArgumentNullException>(() => AsymmetricCryptoUtil.Decrypt(data, keySize, null)); }
public void WhenByteArrayIsNullAndRSAParametersDrecryptThenShouldThrowArgumentNullException() { int keySize = 1024; RSAParameters publicKey; RSAParameters publicAndPrivateKey; AsymmetricCryptoUtil.GenerateKeys(keySize, out publicKey, out publicAndPrivateKey); Assert.ThrowsException <ArgumentNullException>(() => AsymmetricCryptoUtil.Decrypt(null, keySize, publicAndPrivateKey)); }
public void WhenByteArrayKeyIsOutOfRangeAndDecryptAndRSAParametersThenShouldThrowArgumentNullException() { byte[] data = { 10, 47, 67, 10, 91, 15, 33, 25 }; int keySize = 1024; RSAParameters publicKey; RSAParameters publicAndPrivateKey; AsymmetricCryptoUtil.GenerateKeys(keySize, out publicKey, out publicAndPrivateKey); Assert.ThrowsException <ArgumentOutOfRangeException>(() => AsymmetricCryptoUtil.Decrypt(data, int.MaxValue, publicAndPrivateKey)); }
public void WhenByteArrayIsEmptyAndRSAParametersDrecryptThenShouldThrowArgumentNullException() { byte[] data = { 10, 47, 67, 10, 91, 15, 33, 25 }; int keySize = 1024; RSAParameters publicKey; RSAParameters publicAndPrivateKey; AsymmetricCryptoUtil.GenerateKeys(keySize, out publicKey, out publicAndPrivateKey); Assert.ThrowsException <ArgumentNullException>(() => AsymmetricCryptoUtil.Decrypt(new byte[] { }, keySize, publicAndPrivateKey)); }
public void WhenByteArrayIsProvidedAndRSAParameterKeysThenShouldBeAbleToEncryptAndDecryptTest() { byte[] data = { 10, 47, 67, 10, 91, 15, 33, 25 }; int keySize = 1024; RSAParameters publicKey; RSAParameters publicAndPrivateKey; AsymmetricCryptoUtil.GenerateKeys(keySize, out publicKey, out publicAndPrivateKey); var encryptedData = AsymmetricCryptoUtil.Encrypt(data, keySize, publicKey); var decryptedData = AsymmetricCryptoUtil.Decrypt(encryptedData, keySize, publicAndPrivateKey); CollectionAssert.AreNotEqual(data, encryptedData); CollectionAssert.AreEqual(data, decryptedData); }