public void WhenPublicKeyIsNullhenShouldThrowArgumentException() { byte[] data = { 10, 47, 67, 10, 91, 15, 33, 25 }; int keySize = 2048; Assert.ThrowsException <ArgumentNullException>(() => AsymmetricCryptoUtil.Encrypt(data, keySize, null)); }
public void WhenDataToEncryptIsEmptyAndRSAParametersThenShouldThrowArgumentNullException() { int keySize = 1024; RSAParameters publicKey; RSAParameters publicAndPrivateKey; AsymmetricCryptoUtil.GenerateKeys(keySize, out publicKey, out publicAndPrivateKey); Assert.ThrowsException <ArgumentNullException>(() => AsymmetricCryptoUtil.Encrypt(new byte[] { }, keySize, publicKey)); }
public void WhenDataToEncryptIsNullThenShouldThrowArgumentNullException() { int keySize = 1024; string publicKey; string publicAndPrivateKey; AsymmetricCryptoUtil.GenerateKeys(keySize, out publicKey, out publicAndPrivateKey); Assert.ThrowsException <ArgumentNullException>(() => AsymmetricCryptoUtil.Encrypt(null, keySize, publicKey)); }
public void WhenKeySizeIsGreaterThanMaxValueThenShouldThrowArgumentException() { byte[] data = { 10, 47, 67, 10, 91, 15, 33, 25 }; int keySize = 4096; string publicKey; string publicAndPrivateKey; AsymmetricCryptoUtil.GenerateKeys(keySize, out publicKey, out publicAndPrivateKey); Assert.ThrowsException <ArgumentOutOfRangeException>(() => AsymmetricCryptoUtil.Encrypt(data, int.MaxValue, publicKey)); }
public void WhenDataSizeIsGreaterThanMaximumAllowedForKeyAndRSAParametersThenShouldThrowArgumentException() { int keySize = 384; byte[] data = new byte[AsymmetricCryptoUtil.GetMaxDataLength(384) * 2]; Random random = new Random(); random.NextBytes(data); AsymmetricCryptoUtil.GenerateKeys(keySize, out RSAParameters publicKey, out RSAParameters publicAndPrivateKey); Assert.ThrowsException <ArgumentOutOfRangeException>(() => AsymmetricCryptoUtil.Encrypt(data, keySize, publicKey)); }
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); }