c# - DataProtectionProvider.UnprotectAsync(IBuffer) 引发 ASN-1 错误
问题描述
当我尝试运行此代码时,我会在“UnprotectAsync”调用中收到“ASN1 - 值非常大。(来自 HRESULT 的异常:0x80093104)”错误,我不明白为什么。
protectedText 就像 850bytes 位,它很小....
var protectedText = File.ReadAllBytes(this.userDataPath);
string unprotectedText = await this.UnprotectStringAsync(protectedText.AsBuffer());
private async Task<String> UnprotectStringAsync(IBuffer buffProtected)
{
DataProtectionProvider Provider = new DataProtectionProvider();
IBuffer buffUnprotected = await Provider.UnprotectAsync(buffProtected);
String strClearText = CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf8,
buffUnprotected);
return strClearText;
}
解决方案
问题解决了。我不知道我做错了什么,我删除了方法并重写了它。现在它起作用了。