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)

'Declaration
Public Shared Function CreateFromPackage ( _
	envelopeStream As Stream, _
	packageStream As Stream, _
	publishLicense As PublishLicense, _
	cryptoProvider As CryptoProvider _
) As EncryptedPackageEnvelope

Parameters

envelopeStream
Type: System.IO.Stream

The stream on which to create the file.

packageStream
Type: System.IO.Stream

The stream representing the existing unencrypted package.

publishLicense
Type: System.Security.RightsManagement.PublishLicense

The publish license that is embedded in the compound file.

cryptoProvider
Type: System.Security.RightsManagement.CryptoProvider

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

ExceptionCondition
ArgumentNullException

envelopeStream or packageStream is Nothing.

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.

				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

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft