EncryptedPackageEnvelope.IsEncryptedPackageEnvelope Method

Definition

Gets a value specifying whether the file is an OLE compound file with an encrypted package stream.

Overloads

IsEncryptedPackageEnvelope(Stream)

Gets a value specifying whether the specified stream is an OLE compound file with an encrypted package stream.

IsEncryptedPackageEnvelope(String)

Gets a value specifying whether the specified file is an OLE compound file with an encrypted package stream.

IsEncryptedPackageEnvelope(Stream)

Gets a value specifying whether the specified stream is an OLE compound file with an encrypted package stream.

C#
public static bool IsEncryptedPackageEnvelope(System.IO.Stream stream);

Parameters

stream
Stream

The stream that is tested.

Returns

true if the specified stream is an OLE compound file with an encrypted package stream; otherwise, false.

Exceptions

stream is null.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.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, 10

IsEncryptedPackageEnvelope(String)

Gets a value specifying whether the specified file is an OLE compound file with an encrypted package stream.

C#
public static bool IsEncryptedPackageEnvelope(string fileName);

Parameters

fileName
String

The file that is tested.

Returns

true if the specified file is an OLE compound file with an encrypted package stream; otherwise, false.

Exceptions

fileName is null.

Examples

The following example shows how to use this method to test for encryption.

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

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.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, 10