Key generation, serialization and deserialization