c++如何实例化System::Security::Cryptography::Aes?

c++ How to instantiate System::Security::Cryptography::Aes?

我正在尝试使用 Aes 抽象管理 vc++ class 我有以下代码:

using namespace System;
using namespace System::IO;
using namespace System::Security::Cryptography;

namespace Aes_Example
{
    public ref class AesExample : public System::Security::Cryptography::Aes
    {
    public:
        AesExample():Aes(){

        }

    protected :
        ~AesExample(){
        }
    };
}

当我尝试实例化时:

Aes_Example::AesExample^ mAes = gcnew Aes_Example::AesExample();
mAes->Main();

我遇到以下错误

error C2259: 'Aes_Example::AesExample' : cannot instantiate abstract class
1>due to following members:
1>'System::Security::Cryptography::ICryptoTransform ^System::Security::Cryptography::SymmetricAlgorithm::CreateEncryptor(cli::array<unsigned char,1> ^,cli::array<unsigned char,1> ^)' : is abstract
1>c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.0\mscorlib.dll : see declaration of 'System::Security::Cryptography::SymmetricAlgorithm::CreateEncryptor'
1>'System::Security::Cryptography::ICryptoTransform ^System::Security::Cryptography::SymmetricAlgorithm::CreateDecryptor(cli::array<unsigned char,1> ^,cli::array<unsigned char,1> ^)' : is abstract
1>c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.0\mscorlib.dll : see declaration of 'System::Security::Cryptography::SymmetricAlgorithm::CreateDecryptor'
1>'void System::Security::Cryptography::SymmetricAlgorithm::GenerateKey(void)' : is abstract
1>c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.0\mscorlib.dll : see declaration of 'System::Security::Cryptography::SymmetricAlgorithm::GenerateKey'
1>'void System::Security::Cryptography::SymmetricAlgorithm::GenerateIV(void)' : is abstract
1>c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.0\mscorlib.dll : see declaration of 'System::Security::Cryptography::SymmetricAlgorithm::GenerateIV'

System.Security.Cryptography.Aes 是抽象的。

要创建其实例,请使用其 Create() static methods 之一。

或者直接使用 AesManaged class.

没有必要从 Aes 继承(您必须实现 CreateDecryptorCreateEncryptorGenerateIVGenerateKey 方法 SymmetricAlgorithm).