SetCertificate(Stream,String) Method
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.
'Declaration
Public Overloads Function SetCertificate( _
ByVal As Stream, _
ByVal As String _
) As GdPictureStatus
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.
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();