Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Plugin to perform proprietary decryption and encryption during open and save

    Plugin Development
    4
    7
    3383
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Ramon Beiboer
      Ramon Beiboer last edited by

      I have ini files that are encrypted with a proprietary encryption algorithm. It is nothing fancy, but I would like to be able to open these files in Notepad++, edit them and save then again encrypted.
      Is there a way to achieve this by writing a plugin? And if so, can anybody point me into the the right direction how to do this? I have some rusty experience in C++, but I have never built a Notepad++ plugin before, so I do not know if this is possible or not. I prefer to have the plugin decrypt the file when I open it in Notepad++ and encrypt it when I save the file. I do not want to add an extra menu option for encrypting and decrypting, I like to have it transparent.
      An other option would be to invoke a conversion tool when opening the file. The idea is that when the encrypted file is opened, Notepad++ first calls an external tool to convert the file to plain text (for example in the temp folder), and then Notepad++ opens that unencrypted file. I do not care about the security hole that would imply, I just want to be able to edit the file. Would that be possible with Notepad++?

      Thanks!

      1 Reply Last reply Reply Quote 0
      • PeterJones
        PeterJones last edited by

        While a dedicated plugin should work, I think the “invoke a conversion tool when opening the file” is the best.

        For non-automated encrypt/decrypt (I use gpg), I have the following NPP_EXEC macros:

        (ugh, the text version flagged as spam; had to do it via picture, instead. :-( )

        So you could do something like that.

        And using possibly NPP_EXEC and more likely PythonScript or LuaScript, I think you could hook into the load/save actions, so that it would decrypt when you load, allow you to view/edit the decrypted version, but always encrypt again when saving. But I’m not the “hook” expert on the forums, so hopefully someone else will chime in. :-)

        1 Reply Last reply Reply Quote 2
        • dinkumoil
          dinkumoil last edited by

          @Ramon-Beiboer

          If you can change the encryption method of the files you could use the NppCrypt plugin (available via PluginManager). If you have to continue using the current encryption method the code of this plugin may be helpful for you to implement your own plugin. See here.

          1 Reply Last reply Reply Quote 1
          • Ramon Beiboer
            Ramon Beiboer last edited by

            @PeterJones: Thanks for pointing me into the NPP_EXEC direction. Although I might be able to decode and encode the file in Notepad++ with this, it is not exactly what I want. I really want the encoding and decoding to be done automatically when I open or save the file. But I will give it a try and see what I can do with it.

            @dinkumoil: Unfortunately I cannot change the encryption method, the encryption format is already used by released applications.

            1 Reply Last reply Reply Quote 0
            • Ramon Beiboer
              Ramon Beiboer last edited by

              @PeterJones: I tried your suggestion and got something working now. I could not get the line “sci_sendmsg SCI_SELECTALL” working, but I found that SCI_SELECTALL maps to 2013, so “sci_sendmsg 2013” dows work. Why is it that not working in my machine? I am using the NppExec version 0.6 RC1 plugin, is that the correct one? The same goes for SCI_DOCUMENTSTART, that maps to 2316 (I found these values here).

              1 Reply Last reply Reply Quote 1
              • Scott Sumner
                Scott Sumner last edited by

                @PeterJones said:

                …Pythonscript or…But I’m not the “hook” expert on the forums, so hopefully someone else will chime in

                Since the REAL “hook” expert didn’t chime in…she knows who she is… ;)
                I can offer up this:

                Scripting could be a candidate for this, although the true plugin approach is obviously valid as well (just maybe more work)…

                So if you want to see what can be “hooked”–in the file open/close/switch-files realm–and when it gets called as you do things in Notepad++, this Pythonscript code can tell you that (run the code and then watch the Pythonscript console window as you load/save/switch-tabs in Notepad++):

                from Npp import notepad, console, NOTIFICATION
                notepad.callback(lambda x: console.write('FILEBEFORELOAD: {}\r\n'.format(x)),[NOTIFICATION.FILEBEFORELOAD])
                notepad.callback(lambda x: console.write('FILEBEFOREOPEN: {}\r\n'.format(x)),[NOTIFICATION.FILEBEFOREOPEN])
                notepad.callback(lambda x: console.write('FILEOPENED: {}\r\n'.format(x)),[NOTIFICATION.FILEOPENED])
                notepad.callback(lambda x: console.write('BUFFERACTIVATED: {}\r\n'.format(x)),[NOTIFICATION.BUFFERACTIVATED])
                notepad.callback(lambda x: console.write('FILEBEFORECLOSE: {}\r\n'.format(x)),[NOTIFICATION.FILEBEFORECLOSE])
                notepad.callback(lambda x: console.write('FILECLOSED: {}\r\n'.format(x)),[NOTIFICATION.FILECLOSED])
                

                The general idea here would be to decide where it is best to “step in” and do the decrypt/encrypt and then do that in custom written callback functions.

                There are more notifications in Notepad++, perhaps the best way to see more information is to create a new script with the Pythonscript plugin and put the following text into it:

                notepad.callback
                editor.callback
                

                Put your caret on one of those lines and invoke the context-sensitive help.

                Also, look for the section “Handling Notifications” in the Pythonscript docs.

                1 Reply Last reply Reply Quote 1
                • PeterJones
                  PeterJones last edited by PeterJones

                  @Ramon-Beiboer ,

                  Sorry that SCI_SELECTALL didn’t work for you. In my copy of NppExec 0.6 RC1 and 32bit NPP 7.5.6, the exact script I posted works (I just re-ran it to make sure), so I don’t know why it didn’t for you.

                  And thanks, @Scott-Sumner, for chiming in with the hook examples

                  1 Reply Last reply Reply Quote 1
                  • First post
                    Last post
                  Copyright © 2014 NodeBB Forums | Contributors