Null pointer exception on decrypting a file

119 views
Skip to first unread message

Murali V

unread,
Jan 7, 2013, 2:58:13 PM1/7/13
to didisof...@googlegroups.com
Hello ppl,

I am using OpenPGP to encrypt and decrypt files. I have an encrypted file and the private key corresponding to the encryption key. But when I try to use the DecryptFile () method, I get a null pointer exception.. I cannot figure out what the problem is. Any help would be appreciated.
Code:

 public void decryptFile(string filename, string destPath)

string password = "xxx";
                string encFile = System.IO.Path.GetTempPath() + filename;
                string keyFile = ConfigurationManager.AppSettings["DecryptKeyFile"].ToString();
                PGPLib pgpDecrypter = new PGPLib();
                File.Create(destPath + filename);
                string a = pgpDecrypter.DecryptFile(encFile, keyFile, password, destPath+filename);  -- I get the error on this line

didisoft

unread,
Jan 7, 2013, 3:30:09 PM1/7/13
to didisof...@googlegroups.com
Hi Murali,

Can you reproduce this exception with test keys or keys that you can send us,
so we can investigate it on our side?

Cheers,
Peter Kalef
DidiSoft Support

Murali V

unread,
Jan 7, 2013, 3:44:25 PM1/7/13
to didisof...@googlegroups.com
Hello,

Thi sis the deal. I am able to use the same function to successfully decrypt a file which I encrypt using my keys. Do you think it is a problem with the way the file is encrypted?

Thanks

Murali

didisoft

unread,
Jan 7, 2013, 3:54:42 PM1/7/13
to didisof...@googlegroups.com
Hi Murali,

It could be. 

Can you paste here the exception stack trace, this can be of help too.

Kind Regards,
Peter Kalef
DidiSoft Support

Murali V

unread,
Jan 7, 2013, 4:00:15 PM1/7/13
to didisof...@googlegroups.com
Hello,
I am trying to use your example to decrypt the file and I get the error too.
This is the stack trace

   at DidiSoft.Pgp.PGPLib.DecryptFile(FileInfo encryptedFile, FileInfo privateKeyFile, String privateKeyPassword, FileInfo outputFile)
   at FileToolCS.FormMain.btnDecrypt_Click(Object sender, EventArgs e) in C:\Program Files (x86)\OpenPGP Library for .NET 1.7\Examples\FileToolCS\FileToolCS\FormMain.cs:line 273

Thanks

Murali

didisoft

unread,
Jan 14, 2013, 6:12:15 AM1/14/13
to didisof...@googlegroups.com
Hi Murali,

We have introduced a partial verbose logging functionality in the PGPLib class
(the full logging functionality will be available lately this year).

Can you download an updated version of the library and send us the produced verbose log information,
so we can be able to track more closely where does the Null pointer exception happen.

Below is an example how to log the verbose information (with the updated version of the library):

        // your decryption method

        public void decryptFile(string filename, string destPath)
        {
            string password = "xxx";
            string encFile = System.IO.Path.GetTempPath() + filename;
            string keyFile = ConfigurationManager.AppSettings["DecryptKeyFile"].ToString();
            PGPLib pgpDecrypter = new PGPLib();

            pgpDecrypter.LogMessageEvent += Log_Event;

            File.Create(destPath + filename);
            string a = pgpDecrypter.DecryptFile(encFile, keyFile, password, destPath+filename);       
      }

        private void Log_Event(object sender, DidiSoft.Pgp.Logging.LogEventArgs e)
        {
            using (StreamWriter log = File.AppendText(@"c:\Temp\log.txt"))
            {
                log.WriteLine(e.EventTime);
                log.WriteLine(e.Message);
            }
        }

Thank you in advance.

Kind Regards
Peter Kalef
DidiSoft Ltd.
Toll free USA and Canada: 866 253 7568
International 1: (+44) 186-552-1172
International 2: (+359) 895-629-405

07 Jan 2013, 23:00:15 UTC+2, Murali V:

didisoft

unread,
Jan 14, 2013, 8:57:02 AM1/14/13
to didisof...@googlegroups.com
Hi Murali,

Can you please remove the line:

File.Create(destPath + filename);

and tell us is there any difference.

Kind Regards
Peter Kalef
DidiSoft Ltd.
Toll free USA and Canada: 866 253 7568
International 1: (+44) 186-552-1172
International 2: (+359) 895-629-405


Murali V

unread,
Jan 14, 2013, 3:52:09 PM1/14/13
to didisof...@googlegroups.com
Hello,

By removing the File.Create(destPath + filename); part, there is no difference. I used your example "KeyToolsCS" to create the keys for the encryption and decryption. I think the eroor lies in that. Using the same function that i have submitted here I am able to decrypt files that are not encrypted using this key pair. I assume that the error would be with the keys and not with the decrypt method. Thank you for your support and quick replies. I have a new key pair and I am able to decrypt files. 
Thank you

Murali
Reply all
Reply to author
Forward
0 new messages