public void GenerateNewKeyset_Should_ThrowException_When_PublicKeyIsNull()
        {
            // Arrange
            var          key        = new RsaEncryption();
            var          privateKey = new RsaPrivateKey();
            RsaPublicKey publicKey  = null;

            // Act & Assert
            Assert.Throws <ArgumentNullException>(() => key.GenerateNewKeyset(ref publicKey, ref privateKey));
        }
        public void Encrypt_Should_ThrowException_When_DataIsNull()
        {
            // Arrange
            var publicKey  = new RsaPublicKey();
            var privateKey = new RsaPrivateKey();
            var e1         = new RsaEncryption();

            e1.GenerateNewKeyset(ref publicKey, ref privateKey);
            EncryptionData data = null;

            // Act & Assert
            Assert.Throws <ArgumentNullException>(() => e1.Encrypt(data, publicKey));
        }
        public void Encrypt_Should_ThrowException_When_EncryptingToMuchData()
        {
            // Arrange
            var publicKey  = new RsaPublicKey();
            var privateKey = new RsaPrivateKey();
            var e1         = new RsaEncryption();

            // Act
            e1.GenerateNewKeyset(ref publicKey, ref privateKey);

            // Assert
            Assert.Throws <CryptographicException>(() => e1.Encrypt(new EncryptionData(_targetString), publicKey));
        }
        public void Verify_Should_ReturnTrue_When_ValidatingUnChangedSignedData()
        {
            // Arrange
            var secretData = new EncryptionData(Secret);

            var publicKey  = new RsaPublicKey();
            var privateKey = new RsaPrivateKey();
            var e1         = new RsaEncryption();

            e1.GenerateNewKeyset(ref publicKey, ref privateKey);

            // Act
            var signature = e1.Sign(secretData, privateKey);
            var actual    = e1.Verify(secretData, signature, publicKey);

            // Assert
            Assert.True(actual);
        }
        public void Decrypt_Should_ReturnExpectedResult_When_UsingExplicitKeySizeAndGeneratedKeys()
        {
            // Arrange
            var publicKey  = new RsaPublicKey();
            var privateKey = new RsaPrivateKey();

            var e1 = new RsaEncryption(4096);
            var e2 = new RsaEncryption(4096);

            e1.GenerateNewKeyset(ref publicKey, ref privateKey);

            // Act
            var encryptedData = e1.Encrypt(new EncryptionData(Secret), publicKey);
            var decryptedData = e2.Decrypt(encryptedData, privateKey);

            // Assert
            Assert.Equal(decryptedData.Text, Secret);
        }