Compartir vía


EncryptedPackageEnvelope.CreateFromPackage Método

Definición

Crea y devuelve un objeto EncryptedPackageEnvelope que utiliza un paquete no cifrado existente como origen de su contenido.

Sobrecargas

CreateFromPackage(Stream, Stream, PublishLicense, CryptoProvider)

Crea y devuelve un objeto EncryptedPackageEnvelope (en la secuencia especificada) que utiliza el paquete no cifrado especificado como su contenido.

CreateFromPackage(String, Stream, PublishLicense, CryptoProvider)

Crea y devuelve un objeto EncryptedPackageEnvelope que utiliza el paquete no cifrado especificado como su contenido y le asigna el nombre de archivo especificado.

Ejemplos

En el ejemplo siguiente se muestra cómo usar el CreateFromPackage método para crear una instancia de .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 =
    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

CreateFromPackage(Stream, Stream, PublishLicense, CryptoProvider)

Crea y devuelve un objeto EncryptedPackageEnvelope (en la secuencia especificada) que utiliza el paquete no cifrado especificado como su contenido.

public:
 static System::IO::Packaging::EncryptedPackageEnvelope ^ CreateFromPackage(System::IO::Stream ^ envelopeStream, System::IO::Stream ^ packageStream, System::Security::RightsManagement::PublishLicense ^ publishLicense, System::Security::RightsManagement::CryptoProvider ^ cryptoProvider);
public static System.IO.Packaging.EncryptedPackageEnvelope CreateFromPackage (System.IO.Stream envelopeStream, System.IO.Stream packageStream, System.Security.RightsManagement.PublishLicense publishLicense, System.Security.RightsManagement.CryptoProvider cryptoProvider);
static member CreateFromPackage : System.IO.Stream * System.IO.Stream * System.Security.RightsManagement.PublishLicense * System.Security.RightsManagement.CryptoProvider -> System.IO.Packaging.EncryptedPackageEnvelope
Public Shared Function CreateFromPackage (envelopeStream As Stream, packageStream As Stream, publishLicense As PublishLicense, cryptoProvider As CryptoProvider) As EncryptedPackageEnvelope

Parámetros

envelopeStream
Stream

Secuencia en la que se va a crear el archivo.

packageStream
Stream

Secuencia que representa el paquete no cifrado existente.

publishLicense
PublishLicense

Licencia de publicación que está incrustada en el archivo compuesto.

cryptoProvider
CryptoProvider

Objeto que determina las operaciones que puede realizar el usuario actual en el contenido cifrado.

Devoluciones

Colección EncryptedPackageEnvelope creada recientemente.

Excepciones

envelopeStream o packageStream es null.

envelopeStream no proporciona acceso de lectura ni escritura.

Ejemplos

En el ejemplo siguiente se muestra cómo usar el CreateFromPackage método para crear una instancia de .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 =
    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

Comentarios

El usuario actual tiene acceso de lectura y escritura al nuevo archivo.

Consulte también

Se aplica a

CreateFromPackage(String, Stream, PublishLicense, CryptoProvider)

Crea y devuelve un objeto EncryptedPackageEnvelope que utiliza el paquete no cifrado especificado como su contenido y le asigna el nombre de archivo especificado.

public:
 static System::IO::Packaging::EncryptedPackageEnvelope ^ CreateFromPackage(System::String ^ envelopeFileName, System::IO::Stream ^ packageStream, System::Security::RightsManagement::PublishLicense ^ publishLicense, System::Security::RightsManagement::CryptoProvider ^ cryptoProvider);
public static System.IO.Packaging.EncryptedPackageEnvelope CreateFromPackage (string envelopeFileName, System.IO.Stream packageStream, System.Security.RightsManagement.PublishLicense publishLicense, System.Security.RightsManagement.CryptoProvider cryptoProvider);
static member CreateFromPackage : string * System.IO.Stream * System.Security.RightsManagement.PublishLicense * System.Security.RightsManagement.CryptoProvider -> System.IO.Packaging.EncryptedPackageEnvelope
Public Shared Function CreateFromPackage (envelopeFileName As String, packageStream As Stream, publishLicense As PublishLicense, cryptoProvider As CryptoProvider) As EncryptedPackageEnvelope

Parámetros

envelopeFileName
String

Nombre del archivo compuesto OLE.

packageStream
Stream

Secuencia que representa el paquete no cifrado existente.

publishLicense
PublishLicense

Licencia de publicación que está incrustada en el archivo compuesto.

cryptoProvider
CryptoProvider

Objeto que determina las operaciones que puede realizar el usuario actual en el contenido cifrado.

Devoluciones

Colección EncryptedPackageEnvelope creada recientemente.

Excepciones

envelopeFileName o packageStream es null.

Ejemplos

En el ejemplo siguiente se muestra cómo usar el CreateFromPackage método para crear una instancia de .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 =
    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

Comentarios

Si ya existe un archivo con el nombre especificado, se sobrescribe.

El usuario actual tiene acceso de lectura y escritura al archivo.

Consulte también

Se aplica a