简体   繁体   English

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

[英]C# DPAPI must declare a body because it is not marked abstract

I have no idea why i am getting the following error,"must declare a body because it is not marked abstract,extern or partial". 我不知道为什么我得到以下错误,“必须声明一个主体,因为它没有被标记为抽象,外部或部分”。 I actually follow the guide in the following site ' http://www.overclock.net/t/1293731/windows-data-protection-api-c-and-c ' 我实际上遵循以下站点中的指南' 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 */


        }
    }
}

Protect and Unprotect must be implemented if Program is not an abstract class (and it shouldn't be). 如果Program不是抽象类(并且不应是),则必须实现Protect和Unprotect。 However, it doesn't appear that you're using them so maybe just remove them? 但是,您似乎并没有使用它们,所以也许只是删除它们?

As it stands those two methods are abstract prototypes. 就目前而言,这两种方法是抽象原型。

See here for a better example: http://msdn.microsoft.com/en-us/library/system.security.cryptography.protecteddata.aspx 请参阅此处,以获得更好的示例: http : //msdn.microsoft.com/zh-cn/library/system.security.cryptography.protecteddata.aspx

In addition to Jeff's comments, from the rest of your code, it looks like you do not mean to have your own Protect and Unprotect methods and are, instead, calling the ones from the ProtectedData class. 除了Jeff的注释之外,其余的代码看起来也不是要拥有自己的ProtectUnprotect方法,而是从ProtectedData类中调用它们。 If that is the case, you do not need to declare anything in your class for those methods. 在这种情况下,您无需在类中为这些方法声明任何内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#“必须声明一个主体,因为它没有被标记为抽象、外部或部分” - C# “must declare a body because it is not marked abstract, extern, or partial” C#必须声明一个主体,因为它没有被标记为抽象,外部或部分 - C# must declare a body because it is not marked abstract, extern, or partial 必须声明一个主体,因为它没有被标记为抽象的 - must declare a body because it's not marked abstract C# 错误:声明一个主体,因为它没有标记为抽象、外部或部分 - C# errors: declare a body because it is not marked abstract, extern, or partial 错误:必须声明一个主体,因为它没有被标记为抽象,外部或局部 - Error: must declare a body because it is not marked abstract, extern, or partial 出现错误“必须声明一个主体,因为它没有被标记为抽象或外部” - Getting error“must declare a body because it is not marked abstract or extern” 必须声明一个主体,因为它没有标记为抽象外部或局部 - must declare a body because it is not marked abstract extern or partial 访问者必须声明一个主体,因为“属性”未标记为抽象或外部 - Accessor must declare a body because 'property' is not marked as abstract or extern 错误:必须声明一个正文,因为它没有标记为抽象或外部 - Error: must declare a body because it is not marked abstract or extern C#运行时错误声明一个正文,因为它没有标记为abstract,extern或partial - C# Runtime Error Declare a body because it is not marked abstract, extern, or partial
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM