Reference Guide
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. Please always use the GetStat method 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 oGdPicturePDF As New GdPicturePDF()
    'Please see the example in the SetPassword method for creating this file.
    Dim status As GdPictureStatus = oGdPicturePDF.LoadFromFile("encrypted.pdf", False)
    If status = GdPictureStatus.OK Then
        Dim encryption As PdfEncryption = PdfEncryption.PdfEncryptionUnknown
        Dim encrypted As Boolean = oGdPicturePDF.IsEncrypted()
        status = oGdPicturePDF.GetStat()
        If status = GdPictureStatus.OK Then
            If encrypted Then
                'This is incorrect usage.
                encryption = oGdPicturePDF.GetEncryptionScheme()
                If oGdPicturePDF.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 = oGdPicturePDF.SetPassword("user")
                If status = GdPictureStatus.OK Then
                    'The correct usage.
                    encryption = oGdPicturePDF.GetEncryptionScheme() ' correct use
                    If oGdPicturePDF.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 = oGdPicturePDF.GetEncryptionScheme()
                If oGdPicturePDF.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
    oGdPicturePDF.Dispose()
    string caption = "Example: GetEncryptionScheme";
    GdPicturePDF oGdPicturePDF = new GdPicturePDF();
    //Please see the example in the SetPassword method for creating this file.
    GdPictureStatus status = oGdPicturePDF.LoadFromFile("encrypted.pdf", false);
    if (status == GdPictureStatus.OK)
    {
        PdfEncryption encryption = PdfEncryption.PdfEncryptionUnknown;
        bool encrypted = oGdPicturePDF.IsEncrypted();
        status = oGdPicturePDF.GetStat();
        if (status == GdPictureStatus.OK)
        {
            if (encrypted)
            {
                //This is incorrect usage.
                encryption = oGdPicturePDF.GetEncryptionScheme();
                if (oGdPicturePDF.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 = oGdPicturePDF.SetPassword("user");
                if (status == GdPictureStatus.OK)
                {
                     //The correct usage.
                    encryption = oGdPicturePDF.GetEncryptionScheme();
                    if (oGdPicturePDF.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 = oGdPicturePDF.GetEncryptionScheme();
                if (oGdPicturePDF.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);
    }
    oGdPicturePDF.Dispose();
    See Also