GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / GetEncryptionScheme Method
Example





In This Topic
GetEncryptionScheme Method (GdPicturePDF)
In This Topic
Returns the encryption algorithm which has been used to encrypt the currently loaded PDF document.

The PDF specification defines different algorithms to be used to encrypt and/or decrypt a PDF document's content: RC4 40 bits, RC4 128 bits, AES 128 bits, AES 256 bits.

Syntax
'Declaration
 
Public Function GetEncryptionScheme() As PdfEncryption
public PdfEncryption GetEncryptionScheme()
public function GetEncryptionScheme(): PdfEncryption; 
public function GetEncryptionScheme() : PdfEncryption;
public: PdfEncryption GetEncryptionScheme(); 
public:
PdfEncryption GetEncryptionScheme(); 

Return Value

A member of the PdfEncryption enumeration. The GetStat method can be subsequently used to determine if this method has been successful.
Remarks
You should apply this method on a decrypted PDF document only (see the example below).

You need to decrypt the PDF document at first using the SetPassword method with specifyting either the correct user password or the owner password.

Example
How to correctly find out the encryption algorithm that has been used to encrypt the PDF document.
Dim caption As String = "Example: GetEncryptionScheme"
Dim gdpicturePDF As New GdPicturePDF()
'Please see the example in the SetPassword method for creating this file.
Dim status As GdPictureStatus = gdpicturePDF.LoadFromFile("encrypted.pdf", False)
If status = GdPictureStatus.OK Then
    Dim encryption As PdfEncryption = PdfEncryption.PdfEncryptionUnknown
    Dim encrypted As Boolean = gdpicturePDF.IsEncrypted()
    status = gdpicturePDF.GetStat()
    If status = GdPictureStatus.OK Then
        If encrypted Then
            'This is incorrect usage.
            encryption = gdpicturePDF.GetEncryptionScheme()
            If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                MessageBox.Show("This PDF document is encrypted, the encryption scheme is: " + encryption.ToString() + vbCrLf + "Please use SetPassword to decrypt your document.", caption)
            End If
            
            'You need to provide the correct password here.
            status = gdpicturePDF.SetPassword("user")
            If status = GdPictureStatus.OK Then
                'The correct usage.
                encryption = gdpicturePDF.GetEncryptionScheme() ' correct use
                If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                    MessageBox.Show("This PDF document is decrypted, the encryption scheme is: " + encryption.ToString(), caption)
                End If
            Else
                MessageBox.Show("The SetPassword() method has failed with the status: " + status.ToString(), caption)
            End If
        Else
            encryption = gdpicturePDF.GetEncryptionScheme()
            If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                MessageBox.Show("The PDF document is not encrypted, the encryption scheme is: " + encryption.ToString(), caption)
            End If
        End If
    Else
        MessageBox.Show("The IsEncrypted() method has failed with the status: " + status.ToString(), caption)
    End If
Else
    MessageBox.Show("The file can't be loaded.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: GetEncryptionScheme";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
//Please see the example in the SetPassword method for creating this file.
GdPictureStatus status = gdpicturePDF.LoadFromFile("encrypted.pdf", false);
if (status == GdPictureStatus.OK)
{
    PdfEncryption encryption = PdfEncryption.PdfEncryptionUnknown;
    bool encrypted = gdpicturePDF.IsEncrypted();
    status = gdpicturePDF.GetStat();
    if (status == GdPictureStatus.OK)
    {
        if (encrypted)
        {
            //This is incorrect usage.
            encryption = gdpicturePDF.GetEncryptionScheme();
            if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                MessageBox.Show("This PDF document is encrypted, the encryption scheme is: " + encryption.ToString() + "\nPlease use SetPassword to decrypt your document.", caption);
            
            //You need to provide the correct password here.
            status = gdpicturePDF.SetPassword("user");
            if (status == GdPictureStatus.OK)
            {
                 //The correct usage.
                encryption = gdpicturePDF.GetEncryptionScheme();
                if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                    MessageBox.Show("This PDF document is decrypted, the encryption scheme is: " + encryption.ToString(), caption);
            }
            else
            {
                MessageBox.Show("The SetPassword() method has failed with the status: " + status.ToString(), caption);
            }
        }
        else
        {
            encryption = gdpicturePDF.GetEncryptionScheme();
            if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                MessageBox.Show("The PDF document is not encrypted, the encryption scheme is: " + encryption.ToString(), caption);
        }
    }
    else
    {
        MessageBox.Show("The IsEncrypted() method has failed with the status: " + status.ToString(), caption);
    }
}
else
{
    MessageBox.Show("The file can't be loaded.", caption);
}
gdpicturePDF.Dispose();
See Also