Когда я пытаюсь зашифровать и расшифровать образец текста в моем проекте WebAPI, сообщение успешно зашифровано, но при расшифровке оно не работает. Я уже установил в своем startup.cs => services.AddDataProtection (); Вот сообщение об ошибке:
System.Security.Cryptography.CryptographicException: предоставленная полезная нагрузка не может быть расшифрована, поскольку она не была защищена этим поставщиком защиты.
[Route("api/[controller]")]
[ApiController]
public class SecurityController : ControllerBase
{
private readonly IDataProtector _protector;
public SecurityController(IDataProtectionProvider protectionProvider)
{
_protector = protectionProvider.CreateProtector("SampleKey");
}
[HttpGet]
public IActionResult Get()
{
string text = "sample text";
string protectedtext = _protector.Protect(text);
string unprotectedtext = _protector.Unprotect(text);
return Ok(new { text = text, Protected = protectedtext, unprotexted = unprotectedtext });
}
}