CryptoProvider Class
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Provides digital rights management services for encrypting and decrypting protected content.
public ref class CryptoProvider : IDisposable
[System.Security.SecurityCritical(System.Security.SecurityCriticalScope.Everything)]
public class CryptoProvider : IDisposable
public class CryptoProvider : IDisposable
[<System.Security.SecurityCritical(System.Security.SecurityCriticalScope.Everything)>]
type CryptoProvider = class
interface IDisposable
type CryptoProvider = class
interface IDisposable
Public Class CryptoProvider
Implements IDisposable
- Inheritance
-
CryptoProvider
- Attributes
- Implements
The following example shows how to use the CryptoProvider class to create an EncryptedPackageEnvelope.
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
CryptoProvider is created as a result of the Bind method when binding a rights managed UseLicense to a SecureEnvironment.
As with other System.Security.RightsManagement types, CryptoProvider is only usable in full trust applications.
Block |
Gets the cipher block size, in bytes. |
Bound |
Gets a collection listing the rights that passed verification and that are granted to the user. |
Can |
Gets a value that indicates whether the user has rights to decrypt. |
Can |
Gets a value that indicates whether the user has rights to encrypt. |
Can |
Gets a value that indicates whether Encrypt(Byte[]) and Decrypt(Byte[]) can accept buffers that are different block sizes in length. |
Decrypt(Byte[]) |
Decrypts cipher text to clear text. |
Dispose() |
Releases all resources used by the CryptoProvider. |
Dispose(Boolean) |
Releases the unmanaged resources used by the CryptoProvider and optionally releases the managed resources. |
Encrypt(Byte[]) |
Encrypts clear text to cipher text. |
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
Finalize() |
Frees resources and performs internal cleanup before the instance is reclaimed by garbage collection. |
Get |
Serves as the default hash function. (Inherited from Object) |
Get |
Gets the Type of the current instance. (Inherited from Object) |
Memberwise |
Creates a shallow copy of the current Object. (Inherited from Object) |
To |
Returns a string that represents the current object. (Inherited from Object) |
Produto | Versões |
---|---|
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
Comentários do .NET
O .NET é um projeto código aberto. Selecione um link para fornecer comentários: