EncryptedPackageEnvelope.IsEncryptedPackageEnvelope 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取一个值,该值指示文件是否为具有加密包流的 OLE 复合文件。
重载
IsEncryptedPackageEnvelope(Stream) |
获取一个值,该值指示指定的流是否为具有加密包流的 OLE 复合文件。 |
IsEncryptedPackageEnvelope(String) |
获取一个值,该值指示指定的文件是否为具有加密包流的 OLE 复合文件。 |
IsEncryptedPackageEnvelope(Stream)
获取一个值,该值指示指定的流是否为具有加密包流的 OLE 复合文件。
public:
static bool IsEncryptedPackageEnvelope(System::IO::Stream ^ stream);
public static bool IsEncryptedPackageEnvelope (System.IO.Stream stream);
static member IsEncryptedPackageEnvelope : System.IO.Stream -> bool
Public Shared Function IsEncryptedPackageEnvelope (stream As Stream) As Boolean
参数
- stream
- Stream
所测试的流。
返回
如果指定的流是具有加密包流的 OLE 复合文件,则为 true
;否则,为 false
。
例外
stream
为 null
。
适用于
IsEncryptedPackageEnvelope(String)
获取一个值,该值指示指定的文件是否为具有加密包流的 OLE 复合文件。
public:
static bool IsEncryptedPackageEnvelope(System::String ^ fileName);
public static bool IsEncryptedPackageEnvelope (string fileName);
static member IsEncryptedPackageEnvelope : string -> bool
Public Shared Function IsEncryptedPackageEnvelope (fileName As String) As Boolean
参数
- fileName
- String
所测试的文件。
返回
如果指定的文件是具有加密包流的 OLE 复合文件,则为 true
;否则,为 false
。
例外
fileName
为 null
。
示例
以下示例演示如何使用此方法测试加密。
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