Implement key serialization.

Closes #10.