C# Class ComponentFactory.Krypton.Navigator.EncryptedLicenseProvider

Defines a .NET LicenseProvider that uses encrypted licenses generated by the Infralution Licensing System.

The Infralution Licensing System provides a secure way of licensing .NET controls, components and applications. Licenses are protected using public key encryption to minimize possibility of cracking.

Components or controls use the LicenseProviderAttribute to specify this class as the LicenseProvider

Inheritance: System.ComponentModel.LicenseProvider
Exibir arquivo Open project: ComponentFactory/Krypton Class Usage Examples

Private Properties

Property Type Description
ArrayEqual bool
ArraySize int
FromHex byte[]
GetEncryptionKey byte[]
GetLicense EncryptedLicense
LoadLicense EncryptedLicense
Strip string
ToHex string

Public Methods

Method Description
GenerateKey ( string password, string productInfo, UInt16 serialNo ) : string

Generate a new encrypted license using the given password

If there is no installed license for the Infralution Licensing System then the only allowed password is "TEST" and the only allowed serial numbers are 1 or 0. To use the licensed version of this method ensure that the file Infralution.Licensing.EncryptedLicenseProvider.lic exists in the same directory as the Infralution.Licensing.dll and contains a valid license key for the Licensing System.

GenerateLicenseParameters ( string password ) : string

Generate the XML license parameter string that is used to validate licenses generated using the given password

GetLicense ( System.ComponentModel.LicenseContext context, Type type, object instance, bool allowExceptions ) : License
InstallLicense ( Type type, string licenseKey ) : EncryptedLicense

Install a license for the given type.

This method is used by client applications to allow customers to register license for components. The generic Infralution.Licensing.LicenseInstallForm uses this method to install licenses. Client components may implement their own registration forms that call this method. You must call SetParameters before using this method.

SetParameters ( string licenseParameters ) : void

Set the parameters used to validate licenses created by this provider.

This must be called by the client software prior to obtaining licenses using the EncryptedLicenseProvider. The parameters are generated using the Infralution License Key Generator and pasted into the calling client code.

ValidateLicenseKey ( string licenseKey ) : EncryptedLicense

Validate that the given license key is valid for the current licensing parameters

This method provides a mechanism to validate that a given license key is valid prior to attempting to install it. This can be useful if you want to check the EncryptedLicense.ProductInfo before installing the license. You must call SetParameters before using this method.

Protected Methods

Method Description
GetLicenseDirectory ( System.ComponentModel.LicenseContext context, Type type ) : string

Return the directory used to store license files

GetLicenseFilePath ( System.ComponentModel.LicenseContext context, Type type ) : string

Called by GetLicenseKey to get the file path to obtain the license from (if there is no runtime license saved in the context)

This can be overridden to change the file used to store the design time license for the provider. By default the the license file is stored in the same directory as the component executable with the name based on the fully qualified type name eg MyNamespace.MyControl.lic

GetLicenseKey ( System.ComponentModel.LicenseContext context, Type type ) : string

Return the license key for the given context and type

This can be overridden to change where the license key is stored by the provider. For instance a derived class could override this method to store the key in the Registry.

ReadKeyFromFile ( string licenseFile ) : string

Read a license key from the given file

ReadKeyFromRegistry ( ) : string

Grab the key from the registry.

Private Methods

Method Description
ArrayEqual ( byte a1, byte a2 ) : bool

Are the contents of the two byte arrays equal

ArraySize ( int length ) : int

Return the array size to use when declaring an array of the given length.

This is used to account for the difference between declaring VB and C# arrays and permit automatic conversion of the code to VB

FromHex ( string hex ) : byte[]

Converts a hexadecimal string into a byte array.

GetEncryptionKey ( string password ) : byte[]

Generate an 8 byte DES encryption key using the given password

Only the first 7 bytes of the key returned are used. This enables us to reduce the size of the final license keys by 8 bytes.

GetLicense ( string licenseKey, string password ) : EncryptedLicense

Return the license information from the given license key

LoadLicense ( System.ComponentModel.LicenseContext context, Type type, string licenseKey ) : EncryptedLicense

Extract the license for the given type from the given licenseKey

Strip ( string value, string characters ) : string

Return the given input string stripped of the given characters

ToHex ( byte data ) : string

Converts a byte array into a hexadecimal representation.

Method Details

GenerateKey() public method

Generate a new encrypted license using the given password
If there is no installed license for the Infralution Licensing System then the only allowed password is "TEST" and the only allowed serial numbers are 1 or 0. To use the licensed version of this method ensure that the file Infralution.Licensing.EncryptedLicenseProvider.lic exists in the same directory as the Infralution.Licensing.dll and contains a valid license key for the Licensing System.
public GenerateKey ( string password, string productInfo, UInt16 serialNo ) : string
password string The password used to encrypted the license data
productInfo string User defined data about the product being licensed
serialNo System.UInt16 The unique license serial number
return string

GenerateLicenseParameters() public method

Generate the XML license parameter string that is used to validate licenses generated using the given password
public GenerateLicenseParameters ( string password ) : string
password string The password used to encrypted the license data
return string

GetLicense() public method

public GetLicense ( System.ComponentModel.LicenseContext context, Type type, object instance, bool allowExceptions ) : License
context System.ComponentModel.LicenseContext
type System.Type
instance object
allowExceptions bool
return License

GetLicenseDirectory() protected method

Return the directory used to store license files
protected GetLicenseDirectory ( System.ComponentModel.LicenseContext context, Type type ) : string
context System.ComponentModel.LicenseContext The licence context
type System.Type The type being licensed
return string

GetLicenseFilePath() protected method

Called by GetLicenseKey to get the file path to obtain the license from (if there is no runtime license saved in the context)
This can be overridden to change the file used to store the design time license for the provider. By default the the license file is stored in the same directory as the component executable with the name based on the fully qualified type name eg MyNamespace.MyControl.lic
protected GetLicenseFilePath ( System.ComponentModel.LicenseContext context, Type type ) : string
context System.ComponentModel.LicenseContext The licence context
type System.Type The type to get the license for
return string

GetLicenseKey() protected method

Return the license key for the given context and type
This can be overridden to change where the license key is stored by the provider. For instance a derived class could override this method to store the key in the Registry.
protected GetLicenseKey ( System.ComponentModel.LicenseContext context, Type type ) : string
context System.ComponentModel.LicenseContext The license context
type System.Type The type to get the key for
return string

InstallLicense() public method

Install a license for the given type.
This method is used by client applications to allow customers to register license for components. The generic Infralution.Licensing.LicenseInstallForm uses this method to install licenses. Client components may implement their own registration forms that call this method. You must call SetParameters before using this method.
public InstallLicense ( Type type, string licenseKey ) : EncryptedLicense
type System.Type The type to install the license for
licenseKey string The license key to install
return EncryptedLicense

ReadKeyFromFile() protected method

Read a license key from the given file
protected ReadKeyFromFile ( string licenseFile ) : string
licenseFile string The path to the license file to read the key from
return string

ReadKeyFromRegistry() protected method

Grab the key from the registry.
protected ReadKeyFromRegistry ( ) : string
return string

SetParameters() public static method

Set the parameters used to validate licenses created by this provider.
This must be called by the client software prior to obtaining licenses using the EncryptedLicenseProvider. The parameters are generated using the Infralution License Key Generator and pasted into the calling client code.
public static SetParameters ( string licenseParameters ) : void
licenseParameters string An XML string containing parameters used to validate licenses
return void

ValidateLicenseKey() public method

Validate that the given license key is valid for the current licensing parameters
This method provides a mechanism to validate that a given license key is valid prior to attempting to install it. This can be useful if you want to check the EncryptedLicense.ProductInfo before installing the license. You must call SetParameters before using this method.
public ValidateLicenseKey ( string licenseKey ) : EncryptedLicense
licenseKey string The license key to validate
return EncryptedLicense