Added key generating and encode/decode methods.