This documentation is archived and is not being maintained.

RightsManagementInformation.CryptoProvider Property

Gets or sets the CryptoProvider for accessing the package's encrypted rights management data stream.

Namespace:  System.IO.Packaging
Assembly:  WindowsBase (in WindowsBase.dll)

public CryptoProvider CryptoProvider { get; set; }
You cannot set this property in XAML.

Property Value

Type: System.Security.RightsManagement.CryptoProvider
The CryptoProvider for accessing the rights management information.

The following example shows how to set the CryptoProvider property. For the full sample, see Rights Managed Package Viewer Sample.

ShowStatus("   Binding UseLicense with the SecureEnvironment" +
         "\n       to obtain the CryptoProvider.");
rmi.CryptoProvider = useLicense.Bind(_secureEnv);

ShowStatus("   Obtaining BoundGrants.");
grants = rmi.CryptoProvider.BoundGrants;

// You can access the Package via GetPackage() at this point.

rightsBlock.Text = "GRANTS LIST\n-----------\n";
foreach (ContentGrant grant in grants)
    rightsBlock.Text += "USER  :" + grant.User.Name + " [" +
        grant.User.AuthenticationType + "]\n";
    rightsBlock.Text += "RIGHT :" + grant.Right.ToString()+"\n";
    rightsBlock.Text += "    From:  " + grant.ValidFrom + "\n";
    rightsBlock.Text += "    Until: " + grant.ValidUntil + "\n";

The following example shows how to access the CryptoProvider property. For the full sample, see Rights Managed Package Viewer Sample.

if (rmi.CryptoProvider.CanDecrypt == true)
    ShowStatus("   Decryption granted.");
    ShowStatus("   CANNOT DECRYPT!");

ShowStatus("   Getting the Package from\n" +
           "      the EncryptedPackage.");
_xpsPackage = ePackage.GetPackage();
if (_xpsPackage == null)
    MessageBox.Show("Unable to get Package.");
    return false;

// Set a PackageStore Uri reference for the encrypted stream. 
// ("sdk://packLocation" is a pseudo URI used by 
//  PackUriHelper.Create to define the parserContext.BaseURI 
//  that XamlReader uses to access the encrypted data stream.)
Uri packageUri = new Uri(@"sdk://packLocation", UriKind.Absolute);
// Add the URI package
PackageStore.AddPackage(packageUri, _xpsPackage);
// Determine the starting part for the package.
PackagePart startingPart = GetPackageStartingPart(_xpsPackage);

// Set the DocViewer.Document property.
ShowStatus("   Opening in DocumentViewer.");
ParserContext parserContext = new ParserContext();
parserContext.BaseUri = PackUriHelper.Create(
                            packageUri, startingPart.Uri);
parserContext.XamlTypeMapper = XamlTypeMapper.DefaultMapper;
DocViewer.Document = XamlReader.Load(
    startingPart.GetStream(), parserContext)
        as IDocumentPaginatorSource;

// Enable document menu controls.
menuFileClose.IsEnabled = true;
menuFilePrint.IsEnabled = true;
menuViewIncreaseZoom.IsEnabled = true;
menuViewDecreaseZoom.IsEnabled = true;

// Give the DocumentViewer focus.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0