CreateFromPackage Method (Stream, Stream, PublishLicense, CryptoProvider)
Collapse the table of content
Expand the table of content

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
)
public static EncryptedPackageEnvelope CreateFromPackage (
	Stream envelopeStream, 
	Stream packageStream, 
	PublishLicense publishLicense, 
	CryptoProvider cryptoProvider
)
public static function CreateFromPackage (
	envelopeStream : Stream, 
	packageStream : Stream, 
	publishLicense : PublishLicense, 
	cryptoProvider : CryptoProvider
) : EncryptedPackageEnvelope
You cannot use methods in XAML.

Parameters

envelopeStream

The stream on which to create the file.

packageStream

The stream representing the existing unencrypted package.

publishLicense

The publish license that is embedded in the compound file.

cryptoProvider

An object that determines what operations the current user is allowed to perform on the encrypted content.

Return Value

The newly created EncryptedPackageEnvelope.

Exception typeCondition

ArgumentNullException

envelopeStream or packageStream is a null reference (Nothing in Visual Basic).

NotSupportedException

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. For the full sample, see Rights Managed Package Publish Sample.

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

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2016 Microsoft