Running code at the end of import

I am trying to make anki have the ability to import with specifically encrypted decks. In the import function I decrypt the encrypted akpg file (at the very beginning, I figured that part out), and then I would like to re-encrypt those files. In order to prevent messing the process up, I would like to have the encryption part run at the very end of the function.