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.
Static Methods
parse(JsonFactory jsonFactory, String tokenString)
public static JsonWebSignature parse(JsonFactory jsonFactory, String tokenString)
Parses the given JWS token string and returns the parsed JsonWebSignature.
Name | Description |
jsonFactory | JsonFactory JSON factory |
tokenString | String JWS token string |
Type | Description |
JsonWebSignature | parsed JWS |
Type | Description |
IOException |
parser(JsonFactory jsonFactory)
public static JsonWebSignature.Parser parser(JsonFactory jsonFactory)
Returns a new instance of a JWS parser.
Name | Description |
jsonFactory | JsonFactory |
Type | Description |
JsonWebSignature.Parser |
signUsingRsaSha256(PrivateKey privateKey, JsonFactory jsonFactory, JsonWebSignature.Header header, JsonWebToken.Payload payload)
public 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.
Name | Description |
privateKey | PrivateKey private key |
jsonFactory | JsonFactory JSON factory |
header | JsonWebSignature.Header JWS header |
payload | JsonWebToken.Payload JWS payload |
Type | Description |
String | signed JWS string |
Type | Description |
GeneralSecurityException | |
IOException |
Constructors
JsonWebSignature(JsonWebSignature.Header header, JsonWebToken.Payload payload, byte[] signatureBytes, byte[] signedContentBytes)
public JsonWebSignature(JsonWebSignature.Header header, JsonWebToken.Payload payload, byte[] signatureBytes, byte[] signedContentBytes)
Name | Description |
header | JsonWebSignature.Header header |
payload | JsonWebToken.Payload payload |
signatureBytes | byte[] bytes of the signature |
signedContentBytes | byte[] bytes of the signed content |
Methods
getHeader()
public JsonWebSignature.Header getHeader()
Returns the header.
Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
Type | Description |
JsonWebSignature.Header |
getSignatureBytes()
public final byte[] getSignatureBytes()
Returns the bytes of the signature.
Type | Description |
byte[] |
getSignedContentBytes()
public final byte[] getSignedContentBytes()
Returns the bytes of the signature content.
Type | Description |
byte[] |
verifySignature()
public final X509Certificate verifySignature()
Beta
Verifies the signature of the content using the certificate chain embedded in the signature.
Currently only "RS256"
algorithm is verified, but others may be added in the future.
For any other algorithm it returns null
.
The certificate chain is verified using the system default trust manager.
The leaf certificate of the certificate chain must be an SSL server certificate.
Type | Description |
X509Certificate | the signature certificate if the signature could be verified, null otherwise |
Type | Description |
GeneralSecurityException |
verifySignature(PublicKey publicKey)
public final boolean verifySignature(PublicKey publicKey)
Verifies the signature of the content.
Currently only "RS256"
and "ES256"
algorithms are verified, but others may
be added in the future. For any other algorithm it returns false
.
Name | Description |
publicKey | PublicKey public key |
Type | Description |
boolean | whether the algorithm is recognized and it is verified |
Type | Description |
GeneralSecurityException |
verifySignature(X509TrustManager trustManager)
public final X509Certificate verifySignature(X509TrustManager trustManager)
Beta
Verifies the signature of the content using the certificate chain embedded in the signature.
Currently only "RS256"
and "ES256"
algorithms are verified, but others may
be added in the future. For any other algorithm it returns null
.
The leaf certificate of the certificate chain must be an SSL server certificate.
Name | Description |
trustManager | X509TrustManager trust manager used to verify the X509 certificate chain embedded in this message |
Type | Description |
X509Certificate | the signature certificate if the signature could be verified, null otherwise |
Type | Description |
GeneralSecurityException |