UseLicense.Bind Method

Binds the license to a given SecureEnvironment.

Namespace:  System.Security.RightsManagement
Assembly:  WindowsBase (in WindowsBase.dll)

public CryptoProvider Bind(
	SecureEnvironment secureEnvironment
)

Parameters

secureEnvironment
Type: System.Security.RightsManagement.SecureEnvironment

The environment to bind the license to.

Return Value

Type: System.Security.RightsManagement.CryptoProvider
A CryptoProvider instance if the license binding succeeded; otherwise, null.

ExceptionCondition
ArgumentNullException

secureEnvironment is null.

After the license is bound to a secure environment, the application can examine and exercise the rights granted by the license.

The returned CryptoProvider instance provides decryption and access to the protected rights managed content.

The following example shows how to use this method to initialize a CryptoProvider.

WriteStatus("   Signing the UnsignedPublishLicense\n" +
            "       to build the PublishLicense.");
UseLicense authorsUseLicense;
PublishLicense publishLicense =
    unsignedLicense.Sign(_secureEnv, out authorsUseLicense);

WriteStatus("   Binding the author's UseLicense and");
WriteStatus("       obtaining the CryptoProvider.");
CryptoProvider cryptoProvider = authorsUseLicense.Bind(_secureEnv);

WriteStatus("   Creating the EncryptedPackage.");
Stream packageStream = File.OpenRead(packageFile);
EncryptedPackageEnvelope ePackage =
    EncryptedPackageEnvelope.CreateFromPackage(encryptedFile,
        packageStream, publishLicense, cryptoProvider);

WriteStatus("   Adding an author's UseLicense.");
RightsManagementInformation rmi =
    ePackage.RightsManagementInformation;
rmi.SaveUseLicense(author, authorsUseLicense);

ePackage.Close();
WriteStatus("   Done - Package encryption complete.");

WriteStatus("Verifying package encryption.");
if (EncryptedPackageEnvelope.IsEncryptedPackageEnvelope(encryptedFile))
{
    WriteStatus("   Confirmed - '" + encryptedFilename +
                "' is encrypted.");
}
else
{
    MessageBox.Show("ERROR: '" + encryptedFilename +
        "' is NOT ENCRYPTED.", "Encryption Error",
        MessageBoxButton.OK, MessageBoxImage.Error);
    WriteStatus("ERROR: '" + encryptedFilename +
                "' is NOT ENCRYPTED.\n");
    return false;
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft