Refactored existing code and added support for symmetric encryption.

Reading through this example as someone unfamiliar with the library, it's not totally clear to me what `isValid` and `err` mean. In particular, is it the case that `isValid` is true if and only if `err` is nil? The function comment doesn't say, but it should.