GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / SetCertificate Method / SetCertificate(Stream,String) Method
A Stream object specifying the digital ID file. This file contains the certificate given to decrypt the currently loaded PDF document. This Stream object must be initialized and opened for reading before it can be sent into this method and it should remain open for subsequent use.
The password to open the digital ID file specified above.
Example





In This Topic
SetCertificate(Stream,String) Method
In This Topic
Sets the certificate (the associated public key), contained in the digital ID stored in the specified external PKCS#12 file with the filename extension ".p12" or ".pfx". The method works with the instantiated stream object containing the corresponding file.

This method applies the concept of the public key security. It is assumed, that the currently loaded PDF document is encrypted using the provided digital ID. The document is subsequently decrypted using the associated public key.

Syntax
'Declaration
 
Public Overloads Function SetCertificate( _
   ByVal Certificate As Stream, _
   ByVal PFXPassword As String _
) As GdPictureStatus
public GdPictureStatus SetCertificate( 
   Stream Certificate,
   string PFXPassword
)
public function SetCertificate( 
    Certificate: Stream;
    PFXPassword: String
): GdPictureStatus; 
public function SetCertificate( 
   Certificate : Stream,
   PFXPassword : String
) : GdPictureStatus;
public: GdPictureStatus SetCertificate( 
   Stream* Certificate,
   string* PFXPassword
) 
public:
GdPictureStatus SetCertificate( 
   Stream^ Certificate,
   String^ PFXPassword
) 

Parameters

Certificate
A Stream object specifying the digital ID file. This file contains the certificate given to decrypt the currently loaded PDF document. This Stream object must be initialized and opened for reading before it can be sent into this method and it should remain open for subsequent use.
PFXPassword
The password to open the digital ID file specified above.

Return Value

A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK.

We strongly recommend always checking this status first.

Remarks
The public key security handler applies the authentication with a pair of a public key (a certificate) and a private key. In comparison to the standard security handler, this allows you to define individual rights and unique access permissions for different recipients. Only specified recipients will be able to open the encrypted PDF document.

This method requires the Digital Signatures component to run.

Example
How to set a certificate from an instantiated stream object to decrypt the document.
Dim caption As String = "SetCertificate"
Dim gdpicturePDF As New GdPicturePDF()
            
'Specify your digitalID filename here.
Dim digitalID_filename As String = "your_digitalID_filename.pfx"
'Specify the corresponding password here.
Dim password As String = "password"
Dim digitalID_stream As System.IO.FileStream = New system.IO.FileStream(digitalID_filename, FileMode.Open, FileAccess.Read)
            
If gdpicturePDF.LoadFromFile("your_encrypted_document.pdf", False) = GdPictureStatus.OK Then
    Dim status As GdPictureStatus = gdpicturePDF.SetCertificate(digitalID_stream, password)
    MessageBox.Show("The SetCertificate() method has terminated with the status: " + status.ToString(), caption)
    'You can do your stuff with the PDF document here.
Else
    MessageBox.Show("The file can't be loaded.", caption)
End If
gdpicturePDF.Dispose()
digitalID_stream.Dispose()
string caption = "SetCertificate";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
            
//Specify your digitalID filename here.
string digitalID_filename = "your_digitalID_filename.pfx";
//Specify the corresponding password here.
string password = "password";
            
System.IO.FileStream digitalID_stream = new system.IO.FileStream(digitalID_filename, FileMode.Open, FileAccess.Read);
            
if (gdpicturePDF.LoadFromFile("your_encrypted_document.pdf", false) == GdPictureStatus.OK)
{
    GdPictureStatus status = gdpicturePDF.SetCertificate(digitalID_stream, password);
    MessageBox.Show("The SetCertificate() method has terminated with the status: " + status.ToString(),caption);
    //You can do your stuff with the PDF document here.
}
else
{
    MessageBox.Show("The file can't be loaded.", caption);
}
gdpicturePDF.Dispose();
digitalID_stream.Dispose();
See Also