我有两个应用程序Dotnet核心API(3.1)和Blazor服务器,它们都引用了包含DataEncrypt服务的相同dotnet核心lib(3.1)(如下所示)。我从blazor应用程序加密了数据,我也可以解密它。但是,当我尝试使用从blazor服务器加密的API解密相同的数据时,会引发错误“有效负载无效”
public interface IDataEncrypt
{
string EncryptString(string input);
string DecryptString(string encryptedString);
}
public class DataEncrypt : IDataEncrypt
{
private readonly IDataProtector _dataProtector;
public DataEncrypt(IDataProtectionProvider protectionProvider)
{
_dataProtector = protectionProvider.CreateProtector("Key");
}
public string DecryptString(string encryptedString)
=> _dataProtector.Unprotect(encryptedString);
public string EncryptString(string input)
=> _dataProtector.Protect(input);
}