public async Task <ActionResult> GetPassword()
        {
            try
            {
                PasswordResponseModel result = await _passwordGenerator.CreatePasswordAsync(new PasswordRequestModel
                {
                    Length = PasswordLength
                });

                return(Ok(result));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error while generating random password - {ex}", ex.Message);
                return(BadRequest("Please try again."));
            }
        }
        public async Task <ActionResult> CreateRandomPassword(PasswordRequestModel request)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest());
                }


                PasswordResponseModel result = await _passwordGenerator.CreatePasswordAsync(request);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error while generating random password - {ex}", ex.Message);
                return(BadRequest("Please try again."));
            }
        }
        /// <summary>
        /// Encryt Password
        /// </summary>
        /// <param name="plainText"></param>
        /// <param name="salt"></param>
        /// <returns></returns>
        public PasswordResponseModel Encrypt(PasswordRequestModel passwordData)
        {
            var passwordResponse = new PasswordResponseModel()
            {
                InitVectorBytes = passwordData.InitVectorBytes, Salt = passwordData.Salt
            };

            if (passwordResponse.Salt == null || passwordResponse.InitVectorBytes == null)
            {
                passwordResponse.Salt            = CreateSaltOrInitVector();
                passwordResponse.InitVectorBytes = CreateSaltOrInitVector();
            }
            // Convert strings into byte arrays.

            byte[] saltKeyBytes = null;
            saltKeyBytes = Encoding.ASCII.GetBytes(_configuration[keySalt].ToString());

            // Convert our plaintext into a byte array.
            byte[] hashedPasswordBytes = null;

            // Convert our encrypted data from a memory stream into a byte array.
            hashedPasswordBytes = HashPassword(passwordData.PlainText, passwordResponse.Salt);

            // First, we must create a password, from which the key will be derived.
            Rfc2898DeriveBytes key = default(Rfc2898DeriveBytes);

            key = new Rfc2898DeriveBytes(_configuration[passPhrase].ToString(), saltKeyBytes, passwordIterations);

            // Use the password to generate pseudo-random bytes for the encryption
            // key. Specify the size of the key in bytes (instead of bits).
            byte[] keyBytes = null;
            keyBytes = key.GetBytes(keySize / 8);

            // Create uninitialized Rijndael encryption object.
            RijndaelManaged symmetricKey = default(RijndaelManaged);

            symmetricKey = new RijndaelManaged();

            // It is reasonable to set encryption mode to Cipher Block Chaining
            // (CBC). Use default options for other symmetric key parameters.
            symmetricKey.Mode = CipherMode.CBC;

            // Generate encryptor from the existing key bytes and initialization
            // vector. Key size will be defined based on the number of the key
            // bytes.
            ICryptoTransform encryptor = default(ICryptoTransform);

            encryptor = symmetricKey.CreateEncryptor(keyBytes, passwordResponse.InitVectorBytes);

            // Define memory stream which will be used to hold encrypted data.
            MemoryStream memoryStream = default(MemoryStream);

            memoryStream = new MemoryStream();

            // Define cryptographic stream (always use Write mode for encryption).
            CryptoStream cryptoStream = default(CryptoStream);

            cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write);
            // Start encrypting.
            cryptoStream.Write(hashedPasswordBytes, 0, hashedPasswordBytes.Length);

            // Finish encrypting.
            cryptoStream.FlushFinalBlock();

            passwordResponse.CipherTextBytes = memoryStream.ToArray();

            // Close both streams.
            memoryStream.Close();
            cryptoStream.Close();

            // Return encrypted bytes.
            return(passwordResponse);
        }