{"action":"created","issue":{"url":"https://api.github.com/repos/psecio/jwt/issues/9","labels_url":"https://api.github.com/repos/psecio/jwt/issues/9/labels{/name}","comments_url":"https://api.github.com/repos/psecio/jwt/issues/9/comments","events_url":"https://api.github.com/repos/psecio/jwt/issues/9/events","html_url":"https://github.com/psecio/jwt/issues/9","id":44570277,"number":9,"title":"Encrypt generates corrupt signature","user":{"login":"mwillbanks","id":38209,"avatar_url":"https://avatars.githubusercontent.com/u/38209?v=3","gravatar_id":"","url":"https://api.github.com/users/mwillbanks","html_url":"https://github.com/mwillbanks","followers_url":"https://api.github.com/users/mwillbanks/followers","following_url":"https://api.github.com/users/mwillbanks/following{/other_user}","gists_url":"https://api.github.com/users/mwillbanks/gists{/gist_id}","starred_url":"https://api.github.com/users/mwillbanks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mwillbanks/subscriptions","organizations_url":"https://api.github.com/users/mwillbanks/orgs","repos_url":"https://api.github.com/users/mwillbanks/repos","events_url":"https://api.github.com/users/mwillbanks/events{/privacy}","received_events_url":"https://api.github.com/users/mwillbanks/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2014-10-01T14:34:20Z","updated_at":"2015-02-12T20:21:49Z","closed_at":null,"body":"When utilizing the encrypt method there are times when you want to decrypt and verify the token.  Unfortunately this is not possible as the encryption passes the claims encrypted to the encode method.  This causes a corrupt signature thus rendering the verification of the token useless.\r\n\r\nThere are a few different pathways to a solution here...\r\n1. Generate the signature always leveraging the set claims (aka encode does not utilized the passed in claims to generate the signature but rather the classes assigned claims).\r\n2. Pass in a signature and generate it within the encrypt method.\r\n\r\n*Other Thought and Better Approach*\r\nThe library should likely treat decode and encode as a pre-processor and a post-processor.  Meaning that they should _only_ be run on a generated token.  This would then mean the encode and decode have the responsibility of finding their area (aka claims by delimiter), and encoding the result from that standpoint vs. encoding the raw data.  This would make it significantly more clean whilst not destroying the signature. \r\n\r\nIt would be up to the clients in this case to be able to understand how to decode the item."},"comment":{"url":"https://api.github.com/repos/psecio/jwt/issues/comments/74145081","html_url":"https://github.com/psecio/jwt/issues/9#issuecomment-74145081","issue_url":"https://api.github.com/repos/psecio/jwt/issues/9","id":74145081,"user":{"login":"enygma","id":66796,"avatar_url":"https://avatars.githubusercontent.com/u/66796?v=3","gravatar_id":"","url":"https://api.github.com/users/enygma","html_url":"https://github.com/enygma","followers_url":"https://api.github.com/users/enygma/followers","following_url":"https://api.github.com/users/enygma/following{/other_user}","gists_url":"https://api.github.com/users/enygma/gists{/gist_id}","starred_url":"https://api.github.com/users/enygma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/enygma/subscriptions","organizations_url":"https://api.github.com/users/enygma/orgs","repos_url":"https://api.github.com/users/enygma/repos","events_url":"https://api.github.com/users/enygma/events{/privacy}","received_events_url":"https://api.github.com/users/enygma/received_events","type":"User","site_admin":false},"created_at":"2015-02-12T20:21:49Z","updated_at":"2015-02-12T20:21:49Z","body":"I think part of the confusion here is where the encryption comes into play. Right now the encrypt/decrypt methods are trying to encrypt the claims themselves and not just use the OpenSSL stuff for the signature (much like [this library](https://github.com/namshi/jose) does).\r\n\r\nFrom what I can tell in your example code, you're essentially wanting to verify that the encrypted token is correct. My library is a little mixed up on this right now, but I think I'm seeing a way out. The `encode` handling needs to just use whatever hash method is defined in the header and, if it's not HMAC, use the data given to encrypt. The encrypt and decrypt methods, however, need to make the extra step of encrypting the claims too (really this is a JWE, not just a JWT/JWS). I'm trying to figure out the best course of action here to split out the JWT, JWS and JWE functionality and still maintain at least a somewhat similar interface."}}