def decryptfile(self, path):
     with open(path) as f1:
         tmpfile = mktemp(prefix='kina')
         with open(tmpfile, 'wb') as f2:
             iv = f1.read(Cipher.get_blocksize(CIPHERNAME))
             ctxsha256 = sha256()
             ctx = Cipher(self.key, iv, 0,
                          ciphername=CIPHERNAME)
             while True:
                 buff = f1.read(8192)
                 if len(buff) <= 0:
                     break
                 pbuff = ctx.update(buff)
                 ctxsha256.update(pbuff)
                 f2.write(pbuff)
             f2.write(ctx.final())
     move(tmpfile, path)
     return ctxsha256.hexdigest()
 def encryptfile(self, path):
     with open(path) as f1:
         tmpfile = mktemp(prefix='kina')
         with open(tmpfile, 'wb') as f2:
             iv = Cipher.gen_IV(CIPHERNAME)
             ctxsha256 = sha256()
             ctx = Cipher(self.key, iv, 1,
                          ciphername=CIPHERNAME)
             f2.write(iv)
             while True:
                 buff = f1.read(8192)
                 if len(buff) <= 0:
                     break
                 ctxsha256.update(buff)
                 f2.write(ctx.update(buff))
             f2.write(ctx.final())
     move(tmpfile, path)
     return ctxsha256.hexdigest()