public void EncryptOptionsAll()
        {
            byte[]            buffer  = new byte[] { 0, 1, 2, 3 };
            EncryptParameters options = CryptographyModelFactory.EncryptParameters(EncryptionAlgorithm.A128Cbc, buffer, buffer, buffer);

            Assert.AreEqual(EncryptionAlgorithm.A128Cbc, options.Algorithm);
            CollectionAssert.AreEqual(buffer, options.Plaintext);
            CollectionAssert.AreEqual(buffer, options.Iv);
            CollectionAssert.AreEqual(buffer, options.AdditionalAuthenticatedData);
        }
        public void DecryptOptionsOnlyRequired()
        {
            byte[]            buffer  = new byte[] { 0, 1, 2, 3 };
            DecryptParameters options = CryptographyModelFactory.DecryptParameters(EncryptionAlgorithm.A128Cbc, buffer, null, null);

            Assert.AreEqual(EncryptionAlgorithm.A128Cbc, options.Algorithm);
            CollectionAssert.AreEqual(buffer, options.Ciphertext);
            Assert.IsNull(options.Iv);
            Assert.IsNull(options.AuthenticationTag);
            Assert.IsNull(options.AdditionalAuthenticatedData);
        }
        public void DecryptOptionsAll()
        {
            byte[]         buffer  = new byte[] { 0, 1, 2, 3 };
            DecryptOptions options = CryptographyModelFactory.DecryptOptions(EncryptionAlgorithm.A128Cbc, buffer, buffer, buffer);

            options.AdditionalAuthenticatedData = buffer;

            Assert.AreEqual(EncryptionAlgorithm.A128Cbc, options.Algorithm);
            CollectionAssert.AreEqual(buffer, options.Ciphertext);
            CollectionAssert.AreEqual(buffer, options.Iv);
            CollectionAssert.AreEqual(buffer, options.AuthenticationTag);
            CollectionAssert.AreEqual(buffer, options.AdditionalAuthenticatedData);
        }
            /// <summary>
            /// Simulates UnwrapKeyAsync of KeyVault SDK.
            /// </summary>
            /// <param name="algorithm"> Encryption Algorithm </param>
            /// <param name="encryptedKey"> Key to be unwrapped </param>
            /// <param name="cancellationToken"> cancellation token </param>
            /// <returns></returns>
            public override Task <UnwrapResult> UnwrapKeyAsync(KeyWrapAlgorithm algorithm, byte[] encryptedKey, CancellationToken cancellationToken = default)
            {
                if (encryptedKey.IsNullOrEmpty())
                {
                    throw new ArgumentNullException("Key is Null.");
                }

                byte[] unwrappedKey = this.Decrypt(encryptedKey, this.secretkey, this.iv);

                // simulate a null unwrapped key.
                if (this.keyId.ToString().Contains(KeyVaultTestConstants.ValidateNullUnwrappedKey))
                {
                    unwrappedKey = null;
                }

                string       keyid            = "12345678910";
                UnwrapResult mockUnwrapResult = CryptographyModelFactory.UnwrapResult(keyId: keyid, key: unwrappedKey, algorithm: KeyVaultConstants.RsaOaep256);

                return(Task.FromResult(mockUnwrapResult));
            }
 public void EncryptOptionsRequiresPlaintext() =>
 Assert.AreEqual("plaintext", Assert.Throws <ArgumentNullException>(() => CryptographyModelFactory.EncryptParameters(EncryptionAlgorithm.A128Cbc, null)).ParamName);
 public void DecryptOptionsRequiresCiphertext() =>
 Assert.AreEqual("ciphertext", Assert.Throws <ArgumentNullException>(() => CryptographyModelFactory.DecryptOptions(EncryptionAlgorithm.A128Cbc, null)).ParamName);