Share via


RightsManagementInformation.SaveUseLicense(ContentUser, UseLicense) Méthode

Définition

Enregistre une UseLicense donnée pour un utilisateur spécifié sur le flux de données chiffré de gestion des droits.

public:
 void SaveUseLicense(System::Security::RightsManagement::ContentUser ^ userKey, System::Security::RightsManagement::UseLicense ^ useLicense);
public void SaveUseLicense (System.Security.RightsManagement.ContentUser userKey, System.Security.RightsManagement.UseLicense useLicense);
member this.SaveUseLicense : System.Security.RightsManagement.ContentUser * System.Security.RightsManagement.UseLicense -> unit
Public Sub SaveUseLicense (userKey As ContentUser, useLicense As UseLicense)

Paramètres

userKey
ContentUser

Utilisateur de la UseLicense.

useLicense
UseLicense

Licence d'utilisation à stocker et incorporer dans le package.

Exceptions

Le paramètre userKey ou le paramètre useLicense est null.

Les informations de gestion de droits dans ce package ne peuvent pas être lues par la version actuelle de cette classe.

Exemples

L’exemple suivant montre comment utiliser la SaveUseLicense méthode .

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

Remarques

UseLicense Une fois que le pour l’utilisateur spécifié a été enregistré, il peut être récupéré via la LoadUseLicense méthode et à partir de la collection retournée par GetEmbeddedUseLicenses.

Un Package peut stocker les informations de UseLicense droits pour plusieurs utilisateurs de contenu. Chaque ContentUser peut avoir au maximum un UseLicense. Si SaveUseLicense est appelé pour stocker un nouveau UseLicense pour un ContentUser qui a déjà un UseLicense, la licence précédente sera remplacée par la nouvelle licence.

S’applique à

Voir aussi