This documentation is archived and is not being maintained.
MaskGenerationMethod Class
Visual Studio 2010
Represents the abstract class from which all mask generator algorithms must derive.
System::Object
System.Security.Cryptography::MaskGenerationMethod
System.Security.Cryptography::PKCS1MaskGenerationMethod
System.Security.Cryptography::MaskGenerationMethod
System.Security.Cryptography::PKCS1MaskGenerationMethod
Assembly: mscorlib (in mscorlib.dll)
The MaskGenerationMethod type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | MaskGenerationMethod | Initializes a new instance of the MaskGenerationMethod class. |
| Name | Description | |
|---|---|---|
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GenerateMask | When overridden in a derived class, generates a mask with the specified length using the specified random seed. |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
The following code example demonstrates how to derive from the MaskGenerationMethod class.
#using <System.dll> using namespace System; using namespace System::Security::Cryptography; namespace Contoso { ref class MaskGenerator: MaskGenerationMethod { private: String^ hashNameValue; public: // Initialize a mask to encrypt using the SHA1 algorithm. MaskGenerator() { hashNameValue = "SHA1"; } // Create a mask with the specified seed. virtual array<Byte>^ GenerateMask(array<Byte>^ seed, int maskLength) override { HashAlgorithm^ hash; array<Byte>^ rgbCounter = gcnew array<Byte>(4); array<Byte>^ targetRgb = gcnew array<Byte>(maskLength); UInt32 counter = 0; for (int inc = 0; inc < targetRgb->Length; ) { ConvertIntToByteArray(counter++, rgbCounter); hash = (HashAlgorithm^)CryptoConfig::CreateFromName( hashNameValue); array<Byte>^ temp = gcnew array<Byte>( 4 + seed->Length); Buffer::BlockCopy(rgbCounter, 0, temp, 0, 4); Buffer::BlockCopy(seed, 0, temp, 4, seed->Length); hash->ComputeHash(temp); if (targetRgb->Length - inc > hash->HashSize / 8) { Buffer::BlockCopy(hash->Hash, 0, targetRgb, inc, hash->Hash->Length); } else { Buffer::BlockCopy(hash->Hash, 0, targetRgb, inc, targetRgb->Length - inc); } inc += hash->Hash->Length; } return targetRgb; } private: // Convert the specified integer to the byte array. void ConvertIntToByteArray(UInt32 source, array<Byte>^ targetBytes) { UInt32 remainder; int inc = 0; // Clear the array prior to filling it. Array::Clear(targetBytes, 0, targetBytes->Length); while (source > 0) { remainder = source % 256; targetBytes[ 3 - inc ] = (Byte)remainder; source = (source - remainder) / 256; inc++; } } }; // This class demonstrates how to create the MaskGenerator class // and call its GenerateMask member. ref class MaskGeneratorImpl { public: void static Work() { array<Byte>^ seed = gcnew array<Byte>(4){ 0x01,0x02,0x03,0x04}; int length = 16; MaskGenerator^ maskGenerator = gcnew MaskGenerator; array<Byte>^ mask = maskGenerator->GenerateMask(seed, length); Console::WriteLine("Generated the following mask:"); Console::WriteLine(System::Text::Encoding:: ASCII::get()->GetString(mask)); Console::WriteLine("This sample completed successfully;" " press Enter to exit."); Console::ReadLine(); } }; } void main() { Contoso::MaskGeneratorImpl::Work(); } // // This sample produces the following output: // // Generated the following mask: // ?"TFd(?~OtO? // This sample completed successfully; press Enter to exit.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show:
