fixing a bunch of todo's in the encryption code
adds serialization and tests
fixing some tests