CryptoProvider 類別

定義

提供數位版權管理服務,以加密或解密受保護的內容。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
type CryptoProvider = class
    interface IDisposable
Public Class CryptoProvider
Implements IDisposable
繼承
CryptoProvider
屬性
實作

範例

下列範例顯示如何使用CryptoProvider類別來EncryptedPackageEnvelope建立。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會在將管理Bind UseLicense的許可權系結至SecureEnvironment時, 建立為方法的結果。CryptoProvider is created as a result of the Bind method when binding a rights managed UseLicense to a SecureEnvironment.

如同其他System.Security.RightsManagement類型, CryptoProvider只能在完全信任的應用程式中使用。As with other System.Security.RightsManagement types, CryptoProvider is only usable in full trust applications.

屬性

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

取得值,指出 Encrypt(Byte[])Decrypt(Byte[]) 是否可接受區塊長度大小不同的緩衝區。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()

釋放 CryptoProvider 所使用的所有資源。Releases all resources used by the CryptoProvider.

Dispose(Boolean)

釋放 CryptoProvider 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。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.

(繼承來源 Object)
Finalize()

釋出資源並執行內部清除後,記憶體回收才能回收執行個體。Frees resources and performs internal cleanup before the instance is reclaimed by garbage collection.

GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

適用於

另請參閱