This documentation is archived and is not being maintained.

EncryptedPackageEnvelope.CreateFromPackage Method (Stream, Stream, PublishLicense, CryptoProvider)

Creates and returns an EncryptedPackageEnvelope (on the specified stream) that uses the specified unencrypted package as its content.

Namespace:  System.IO.Packaging
Assembly:  WindowsBase (in WindowsBase.dll)

public static EncryptedPackageEnvelope CreateFromPackage(
	Stream envelopeStream,
	Stream packageStream,
	PublishLicense publishLicense,
	CryptoProvider cryptoProvider


Type: System.IO.Stream
The stream on which to create the file.
Type: System.IO.Stream
The stream representing the existing unencrypted package.
Type: System.Security.RightsManagement.PublishLicense
The publish license that is embedded in the compound file.
Type: System.Security.RightsManagement.CryptoProvider
An object that determines what operations the current user is allowed to perform on the encrypted content.


envelopeStream or packageStream is null.


envelopeStream does not provide read/write access.

The current user has read/write access to the new file.

The following example shows how to use the CreateFromPackage method to instantiate 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 =
        packageStream, publishLicense, cryptoProvider);

WriteStatus("   Adding an author's UseLicense.");
RightsManagementInformation rmi =
rmi.SaveUseLicense(author, authorsUseLicense);

WriteStatus("   Done - Package encryption complete.");

WriteStatus("Verifying package encryption.");
if (EncryptedPackageEnvelope.IsEncryptedPackageEnvelope(encryptedFile))
    WriteStatus("   Confirmed - '" + encryptedFilename +
                "' is encrypted.");
    MessageBox.Show("ERROR: '" + encryptedFilename +
        "' is NOT ENCRYPTED.", "Encryption Error",
        MessageBoxButton.OK, MessageBoxImage.Error);
    WriteStatus("ERROR: '" + encryptedFilename +
                "' is NOT ENCRYPTED.\n");
    return false;

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.