using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Mvc;
using SimpleDataProtection_final.Models;

namespace SimpleDataProtection_final.Controllers {
    public class HomeController : Controller {
        IDataProtector protector;

        public HomeController(IDataProtectionProvider provider) {
            this.protector = provider.CreateProtector("my sample purpose");
        }

        public IActionResult Index() {
            var inputString = "Hello, World!";
            var protectedString = this.protector.Protect(inputString);
            var unprotectedString = this.protector.Unprotect(protectedString);

            var sb = new StringBuilder();
            sb.AppendLine($"Original string:    {inputString}");
            sb.AppendLine($"Protected string:   {protectedString}");
            sb.AppendLine($"Unprotected string: {unprotectedString}");
            var model = sb.ToString();

            return View("Index", model);
        }

    }
}
