CryptoProvider Class

Definition

Provides digital rights management services for encrypting and decrypting protected content.

[System.Security.SecurityCritical(System.Security.SecurityCriticalScope.Everything)]
public class CryptoProvider : IDisposable
public class CryptoProvider : IDisposable
Inheritance
CryptoProvider
Attributes
Implements

Examples

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;
}

Remarks

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.

Properties

BlockSize

Gets the cipher block size, in bytes.

BoundGrants

Gets a collection listing the rights that passed verification and that are granted to the user.

CanDecrypt

Gets a value that indicates whether the user has rights to decrypt.

CanEncrypt

Gets a value that indicates whether the user has rights to encrypt.

CanMergeBlocks

Gets a value that indicates whether Encrypt(Byte[]) and Decrypt(Byte[]) can accept buffers that are different block sizes in length.

Methods

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.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

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

See also