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 as specified in
Reserved Header Parameter Names.
|
static class |
JsonWebSignature
JWS parser.
|
JsonWebToken.Payload | Constructor and Description |
|---|
JsonWebSignature(JsonWebSignature
|
| Modifier and Type | Method and Description |
|---|---|
JsonWebSignature |
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
Parses the given JWS token string and returns the parsed
JsonWebSignature.
|
static JsonWebSignature |
parser(JsonFactory
Returns a new instance of a JWS parser.
|
static String |
signUsingRsaSha256(PrivateKey
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.
|
X509Certificate |
verifySignature()
Beta
Verifies the signature of the content using the certificate chain embedded in the signature. |
boolean |
verifySignature(PublicKey
Verifies the signature of the content.
|
X509Certificate |
verifySignature(X509TrustManager
Beta
Verifies the signature of the content using the certificate chain embedded in the signature. |
getPayload, toStringpublic JsonWebSignature(JsonWebSignature.Header header, JsonWebToken .Payload payload, byte[] signatureBytes, byte[] signedContentBytes)
header - header
payload - payload
signatureBytes - bytes of the signature
signedContentBytes - bytes of the signature content
public JsonWebSignature.Header getHeader()
JsonWebToken
Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
public final boolean verifySignature(PublicKeypublicKey) 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 key
GeneralSecurityException -
@Beta public final X509CertificateverifySignature(X509TrustManager trustManager) throws GeneralSecurityException
Beta
Currently only "RS256" algorithm is 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.
trustManager - Trust manager used to verify the X509 certificate chain embedded in this message.
GeneralSecurityException -
@Beta public final X509CertificateverifySignature() throws GeneralSecurityException
Beta
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.
GeneralSecurityException -
public final byte[] getSignatureBytes()
public final byte[] getSignedContentBytes()
public static JsonWebSignatureparse(JsonFactory jsonFactory, String tokenString) throws IOException
JsonWebSignature.
jsonFactory - JSON factory
tokenString - JWS token string
IOException
public static JsonWebSignature.Parser parser(JsonFactory jsonFactory)
public static StringsignUsingRsaSha256(PrivateKey privateKey, JsonFactory jsonFactory, JsonWebSignature .Header header, JsonWebToken .Payload payload) throws GeneralSecurityException , IOException
privateKey - private key
jsonFactory - JSON factory
header - JWS header
payload - JWS payload
GeneralSecurityException
IOException