CryptoProvider 类

定义

为加密和解密受保护的内容提供数字权限管理服务。

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
继承
CryptoProvider
属性
实现

示例

以下示例演示如何使用 CryptoProvider 类创建 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在将管理UseLicenseSecureEnvironment的权限绑定到 时,作为 方法创建的结果Bind

与其他 System.Security.RightsManagement 类型一样, CryptoProvider 仅在完全信任应用程序中可用。

属性

BlockSize

获取密码块大小(以字节为单位)。

BoundGrants

获取一个集合,该集合列出已通过验证并授予用户的权限。

CanDecrypt

获取一个指示用户是否有解密权限的值。

CanEncrypt

获取一个指示用户是否有加密权限的值。

CanMergeBlocks

获取一个值,该值指示 Encrypt(Byte[])Decrypt(Byte[]) 是否可以接受块长度不同的缓冲区。

方法

Decrypt(Byte[])

将密码文本解密为明文。

Dispose()

释放由 CryptoProvider 使用的所有资源。

Dispose(Boolean)

释放由 CryptoProvider 占用的非托管资源,还可以另外再释放托管资源。

Encrypt(Byte[])

将明文加密为密文。

Equals(Object)

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

(继承自 Object)
Finalize()

在通过垃圾回收将实例回收之前,释放资源并执行内部清理。

GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

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

(继承自 Object)

适用于

另请参阅