public class JsonWebSignature extends JsonWebToken
Sample usage:
public static void printPayload(JsonFactory jsonFactory, String tokenString) throws IOException { JsonWebSignature jws = JsonWebSignature.parse(jsonFactory, tokenString); System.out.println(jws.getPayload()); }
Implementation is not thread-safe.
Modifier and Type | Class and Description |
---|---|
static class |
JsonWebSignature.Header
Header as specified in Reserved
Header Parameter Names.
|
static class |
JsonWebSignature.Parser
JWS parser.
|
JsonWebToken.Payload
Constructor and Description |
---|
JsonWebSignature(JsonWebSignature.Header header,
JsonWebToken.Payload payload,
byte[] signatureBytes,
byte[] signedContentBytes) |
Modifier and Type | Method and Description |
---|---|
JsonWebSignature.Header |
getHeader()
Returns the header.
|
byte[] |
getSignatureBytes()
Returns the modifiable array of bytes of the signature.
|
byte[] |
getSignedContentBytes()
Returns the modifiable array of bytes of the signature content.
|
static JsonWebSignature |
parse(JsonFactory jsonFactory,
String tokenString)
Parses the given JWS token string and returns the parsed
JsonWebSignature . |
static JsonWebSignature.Parser |
parser(JsonFactory jsonFactory)
Returns a new instance of a JWS parser.
|
static String |
signUsingRsaSha256(PrivateKey privateKey,
JsonFactory jsonFactory,
JsonWebSignature.Header header,
JsonWebToken.Payload payload)
Signs a given JWS header and payload based on the given private key using RSA and SHA-256 as
described in JWS using
RSA SHA-256.
|
boolean |
verifySignature(PublicKey publicKey)
Verifies the signature of the content.
|
getPayload, toString
public JsonWebSignature(JsonWebSignature.Header header, JsonWebToken.Payload payload, byte[] signatureBytes, byte[] signedContentBytes)
header
- headerpayload
- payloadsignatureBytes
- bytes of the signaturesignedContentBytes
- bytes of the signature contentpublic JsonWebSignature.Header getHeader()
JsonWebToken
Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
getHeader
in class JsonWebToken
public final boolean verifySignature(PublicKey publicKey) throws GeneralSecurityException
Currently only "RS256"
algorithm is verified, but others may be added in the future.
For any other algorithm it returns false
.
publicKey
- public keyGeneralSecurityException
public final byte[] getSignatureBytes()
public final byte[] getSignedContentBytes()
public static JsonWebSignature parse(JsonFactory jsonFactory, String tokenString) throws IOException
JsonWebSignature
.jsonFactory
- JSON factorytokenString
- JWS token stringIOException
public static JsonWebSignature.Parser parser(JsonFactory jsonFactory)
public static String signUsingRsaSha256(PrivateKey privateKey, JsonFactory jsonFactory, JsonWebSignature.Header header, JsonWebToken.Payload payload) throws GeneralSecurityException, IOException
privateKey
- private keyjsonFactory
- JSON factoryheader
- JWS headerpayload
- JWS payloadGeneralSecurityException
IOException
Copyright © 2011-2013 Google. All Rights Reserved.