gpt4 book ai didi

C# DPAPI 必须声明一个主体,因为它没有标记为抽象

转载 作者:太空宇宙 更新时间:2023-11-03 15:58:14 25 4
gpt4 key购买 nike

我不知道为什么会出现以下错误,“必须声明一个主体,因为它没有标记为抽象、外部或部分”。我实际上遵循以下站点中的指南'http://www.overclock.net/t/1293731/windows-data-protection-api-c-and-c '

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace DataProtection
{
class Program
{
public static byte[] Protect(byte[] userData, byte[] optionalEntropy, DataProtectionScope scope);
public static byte[] Unprotect(byte[] encryptedData, byte[] optionalEntropy, DataProtectionScope scope);

static void Main(string[] args)
{
string plainText = "I have less headaches in the managed world!";
byte[] plainTextBytes = Encoding.Unicode.GetBytes(plainText);

/* Call the method. The return value is a byte array of ENCRYPTED data */
byte[] encrypted = ProtectedData.Protect(
plainTextBytes, /* our byte array to be encrypted */
null, /* we can pass additional entropy in the form of a byte array (optional) */
DataProtectionScope.CurrentUser /* can also pass DataProtectionScope.LocalMachine */
);

/* Here we might write out the bytes in "encypted" to disk */


}
}
}

最佳答案

如果 Program 不是抽象类(不应该是),则必须实现 Protect 和 Unprotect。但是,您似乎没有使用它们,所以也许只是删除它们?

就目前而言,这两个方法是抽象原型(prototype)。

请参阅此处以获得更好的示例:http://msdn.microsoft.com/en-us/library/system.security.cryptography.protecteddata.aspx

关于C# DPAPI 必须声明一个主体,因为它没有标记为抽象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22550155/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com