UseLicense.Bind(SecureEnvironment) Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Associa la licenza a un oggetto SecureEnvironment specificato.
public:
System::Security::RightsManagement::CryptoProvider ^ Bind(System::Security::RightsManagement::SecureEnvironment ^ secureEnvironment);
public System.Security.RightsManagement.CryptoProvider Bind (System.Security.RightsManagement.SecureEnvironment secureEnvironment);
member this.Bind : System.Security.RightsManagement.SecureEnvironment -> System.Security.RightsManagement.CryptoProvider
Public Function Bind (secureEnvironment As SecureEnvironment) As CryptoProvider
Parametri
- secureEnvironment
- SecureEnvironment
Ambiente a cui associare la licenza.
Restituisce
Istanza di CryptoProvider se l'associazione della licenza riesce. In caso contrario, null
.
Eccezioni
secureEnvironment
è null
.
Esempio
Nell'esempio seguente viene illustrato come utilizzare questo metodo per inizializzare un oggetto 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;
}
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
Commenti
Dopo che la licenza è associata a un ambiente sicuro, l'applicazione può esaminare ed esercitare i diritti concessi dalla licenza.
L'istanza restituita CryptoProvider fornisce la decrittografia e l'accesso al contenuto protetto gestito dai diritti.