RightsManagementInformation 类

定义

表示存储在 EncryptedPackageEnvelope 中的数字版权管理 (DRM) 信息。

public ref class RightsManagementInformation
public class RightsManagementInformation
type RightsManagementInformation = class
Public Class RightsManagementInformation
继承
RightsManagementInformation

示例

以下示例演示如何初始化 RightsManagementInformation 用于加密的 对象。

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;
}
WriteStatus("   Signing the UnsignedPublishLicense" & vbLf & "       to build the PublishLicense.")
Dim authorsUseLicense As UseLicense = Nothing
Dim publishLicense As PublishLicense = unsignedLicense.Sign(_secureEnv, authorsUseLicense)

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

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

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

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

WriteStatus("Verifying package encryption.")
If EncryptedPackageEnvelope.IsEncryptedPackageEnvelope(encryptedFile) Then
    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." & vbLf)
    Return False
End If

下面的示例演示如何初始化 RightsManagementInformation 用于解密的 对象。

ShowStatus("   Opening the encrypted Package.");
EncryptedPackageEnvelope ePackage =
    EncryptedPackageEnvelope.Open(xpsFile, FileAccess.ReadWrite);
RightsManagementInformation rmi =
    ePackage.RightsManagementInformation;

ShowStatus("   Looking for an embedded UseLicense for user:\n       " +
           currentUserId + " [" + _authentication + "]");
UseLicense useLicense =
    rmi.LoadUseLicense(
        new ContentUser(currentUserId, _authentication));

ReadOnlyCollection<ContentGrant> grants;
if (useLicense == null)
{
    ShowStatus("   No Embedded UseLicense found.\n       " +
               "Attempting to acqure UseLicnese\n       " +
               "from the PublishLicense.");
    PublishLicense pubLicense = rmi.LoadPublishLicense();

    ShowStatus("   Referral information:");

    if (pubLicense.ReferralInfoName == null)
        ShowStatus("       Name: (null)");
    else
        ShowStatus("       Name: " + pubLicense.ReferralInfoName);

    if (pubLicense.ReferralInfoUri == null)
        ShowStatus("    Uri: (null)");
    else
        ShowStatus("    Uri: " +
            pubLicense.ReferralInfoUri.ToString());

    useLicense = pubLicense.AcquireUseLicense(_secureEnv);
    if (useLicense == null)
    {
        ShowStatus("   User DOES NOT HAVE RIGHTS\n       " +
            "to access this document!");
        return false;
    }
}// end:if (useLicense == null)
ShowStatus("   UseLicense acquired.");
ShowStatus("   Opening the encrypted Package.")
Dim ePackage As EncryptedPackageEnvelope = EncryptedPackageEnvelope.Open(xpsFile, FileAccess.ReadWrite)
Dim rmi As RightsManagementInformation = ePackage.RightsManagementInformation

ShowStatus("   Looking for an embedded UseLicense for user:" & vbLf & "       " & currentUserId & " [" & _authentication & "]")
Dim useLicense As UseLicense = rmi.LoadUseLicense(New ContentUser(currentUserId, _authentication))

Dim grants As ReadOnlyCollection(Of ContentGrant)
If useLicense Is Nothing Then
    ShowStatus("   No Embedded UseLicense found." & vbLf & "       " & "Attempting to acqure UseLicnese" & vbLf & "       " & "from the PublishLicense.")
    Dim pubLicense As PublishLicense = rmi.LoadPublishLicense()

    ShowStatus("   Referral information:")

    If pubLicense.ReferralInfoName Is Nothing Then
        ShowStatus("       Name: (null)")
    Else
        ShowStatus("       Name: " & pubLicense.ReferralInfoName)
    End If

    If pubLicense.ReferralInfoUri Is Nothing Then
        ShowStatus("    Uri: (null)")
    Else
        ShowStatus("    Uri: " & pubLicense.ReferralInfoUri.ToString())
    End If

    useLicense = pubLicense.AcquireUseLicense(_secureEnv)
    If useLicense Is Nothing Then
        ShowStatus("   User DOES NOT HAVE RIGHTS" & vbLf & "       " & "to access this document!")
        Return False
    End If
End If ' end:if (useLicense == null)
ShowStatus("   UseLicense acquired.")

注解

RightsManagementInformation提供对PublishLicense存储在权限管理的受保护 Package中的 和 UseLicense 数据的访问权限。

属性

CryptoProvider

获取或设置用于访问包的加密权限管理数据流的 CryptoProvider

方法

DeleteUseLicense(ContentUser)

从加密权限管理数据流中删除指定用户的 UseLicense

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetEmbeddedUseLicenses()

从加密权限管理数据流返回用户和 UseLicense 键/值对的字典集合。

GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
LoadPublishLicense()

从加密权限管理数据流返回嵌入的 PublishLicense

LoadUseLicense(ContentUser)

从加密权限管理数据流返回指定用户的嵌入 UseLicense

MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
SavePublishLicense(PublishLicense)

将给定的 PublishLicense 保存到加密权限管理数据流。

SaveUseLicense(ContentUser, UseLicense)

将指定用户的给定 UseLicense 保存到加密权限管理数据流。

ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅