本文整理汇总了Java中org.jose4j.jws.JsonWebSignature.setCompactSerialization方法的典型用法代码示例。如果您正苦于以下问题:Java JsonWebSignature.setCompactSerialization方法的具体用法?Java JsonWebSignature.setCompactSerialization怎么用?Java JsonWebSignature.setCompactSerialization使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jose4j.jws.JsonWebSignature
的用法示例。
在下文中一共展示了JsonWebSignature.setCompactSerialization方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifyJwsSignature
import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
/**
* Verify jws signature byte [ ].
*
* @param value the value
* @param signingKey the signing key
* @return the byte [ ]
*/
public static byte[] verifyJwsSignature(final Key signingKey, final byte[] value) {
try {
final String asString = new String(value, StandardCharsets.UTF_8);
final JsonWebSignature jws = new JsonWebSignature();
jws.setCompactSerialization(asString);
jws.setKey(signingKey);
final boolean verified = jws.verifySignature();
if (verified) {
final String payload = jws.getPayload();
LOGGER.trace("Successfully decoded value. Result in Base64-encoding is [{}]", payload);
return EncodingUtils.decodeBase64(payload);
}
return null;
} catch (final Exception e) {
throw Throwables.propagate(e);
}
}
示例2: verifySignature
import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
/**
* Verify signature.
*
* @param value the value
* @return the value associated with the signature, which may have to
* be decoded, or null.
*/
protected byte[] verifySignature(@NotNull final byte[] value) {
try {
final String asString = new String(value);
final JsonWebSignature jws = new JsonWebSignature();
jws.setCompactSerialization(asString);
jws.setKey(this.signingKey);
final boolean verified = jws.verifySignature();
if (verified) {
final String payload = jws.getPayload();
logger.debug("Successfully decoded value. Result in Base64-encoding is [{}]", payload);
return CompressionUtils.decodeBase64(payload);
}
return null;
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
示例3: verifySignature
import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
/**
* Verify signature.
*
* @param value the value
* @return the value associated with the signature, which may have to
* be decoded, or null.
*/
private String verifySignature(@NotNull final String value) {
try {
final JsonWebSignature jws = new JsonWebSignature();
jws.setCompactSerialization(value);
jws.setKey(this.secretKeySigningKey);
final boolean verified = jws.verifySignature();
if (verified) {
logger.debug("Signature successfully verified. Payload is [{}]", jws.getPayload());
return jws.getPayload();
}
return null;
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
示例4: verify
import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
@Override
public boolean verify(String authToken, String issuer) {
Preconditions.checkNotNull(authToken);
Preconditions.checkNotNull(issuer);
try {
JsonWebKeySet jwks = this.jwksSupplier.supply(issuer);
JsonWebSignature jws = new JsonWebSignature();
jws.setCompactSerialization(authToken);
for (JsonWebKey jwk : this.jwkSelector.selectList(jws, jwks.getJsonWebKeys())) {
jws.setKey(jwk.getKey());
if (jws.verifySignature()) {
return true;
}
}
} catch (JoseException exception) {
throw new UnauthenticatedException("Cannot verify the signature", exception);
}
return false;
}
示例5: verifySignature
import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
/**
* Verify signature.
*
* @param value the value
* @return the value associated with the signature, which may have to
* be decoded, or null.
*/
protected byte[] verifySignature(@NotNull final byte[] value) {
try {
final String asString = new String(value);
final JsonWebSignature jws = new JsonWebSignature();
jws.setCompactSerialization(asString);
jws.setKey(this.signingKey);
final boolean verified = jws.verifySignature();
if (verified) {
final String payload = jws.getPayload();
logger.debug("Successfully decoded value. Result in Base64-encoding is [{}]", payload);
return CompressionUtils.decodeBase64ToByteArray(payload);
}
return null;
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
示例6: noKidTestNovJwksEndpoint
import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
@Test
public void noKidTestNovJwksEndpoint() throws JoseException
{
// JSON content from https://connect-op.herokuapp.com/jwks.json on Jan 8, 2015
String json = "{\"keys\":[" +
"{\"kty\":\"RSA\"," +
"\"e\":\"AQAB\"," +
"\"n\":\"pKybs0WaHU_y4cHxWbm8Wzj66HtcyFn7Fh3n-99qTXu5yNa30MRYIYfSDwe9JVc1JUoGw41yq2StdGBJ40HxichjE-Yopfu3B58QlgJvToUbWD4gmTDGgMGxQxtv1En2yedaynQ73sDpIK-12JJDY55pvf-PCiSQ9OjxZLiVGKlClDus44_uv2370b9IN2JiEOF-a7JBqaTEYLPpXaoKWDSnJNonr79tL0T7iuJmO1l705oO3Y0TQ-INLY6jnKG_RpsvyvGNnwP9pMvcP1phKsWZ10ofuuhJGRp8IxQL9RfzT87OvF0RBSO1U73h09YP-corWDsnKIi6TbzRpN5YDw\"" +
",\"use\":\"sig\"}]}";
JsonWebKeySet jwks = new JsonWebKeySet(json);
VerificationJwkSelector verificationJwkSelector = new VerificationJwkSelector();
JsonWebSignature jws = new JsonWebSignature();
jws.setCompactSerialization("eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJodHRwczovL2Nvbm5lY3Qtb3AuaGVyb2t1YXBwLmNvbSIsInN1YiI6IjZiOTYyYzk1Nzk4NThkNzJjNjY0M2FiZjhkN2E2ZWJjIiwiYXVkIjoiZGIwZTdmYTNmNmQwN2ZhMjYzMjZhNzE4NjQwMGVhOTEiLCJleHAiOjE0MjA3NTI0NzAsImlhdCI6MTQyMDczMDg3MCwibm9uY2UiOiJiOGU1OTlhM2JkYTRkNDExYzhiMDc0OGM1MGQwZjQxNyJ9.FNyq7K90vW7eLmsjzUPQ8eTnTreOWXVt_WKyqS686_D_kZ9tl3_uE3tKBw004XyFwMYd-4zWhvXaDPkhFGJ6BPy_woxnQdiTobNE-jyQscp6-6keg3QRkjV-Te7F48Pyfzl-lwvzhb76ygjuv7v_1Nf49fHZb-SiQ2KmapabHpIfVvuqTQ_MZjU613XJIW0tMqFv4__fgaZD-JU6qCkVbkXpvIMg_tZDafsipJ6ZYH9_9JuXQqjzmsM6vHN53MiQZaDtwb6nLDFln6YPqmVPXJV6SLvM_vn0g5w6jvmfsPGZL-xo-iqWbYtnMK-dX4HmnLpK4JVba_OnA9NQfj2DRQ");
List<JsonWebKey> jsonWebKeys = jwks.getJsonWebKeys();
List<JsonWebKey> selected = verificationJwkSelector.selectList(jws, jsonWebKeys);
assertThat(1, equalTo(selected.size()));
JsonWebKey jsonWebKey = selected.get(0);
jws.setKey(jsonWebKey.getKey());
assertTrue(jws.verifySignature());
}
示例7: verifySignature
import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
/**
* Verify signature.
*
* @param value the value
* @return the value associated with the signature, which may have to
* be decoded, or null.
*/
private String verifySignature(@NotNull final String value) {
try {
final JsonWebSignature jws = new JsonWebSignature();
jws.setCompactSerialization(value);
jws.setKey(this.secretKeySigningKey);
final boolean verified = jws.verifySignature();
if (verified) {
LOGGER.debug("Signature successfully verified. Payload is [{}]", jws.getPayload());
return jws.getPayload();
}
return null;
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
示例8: verifyJwsCompactSerialization
import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
@Override
public boolean verifyJwsCompactSerialization(String jwsCompactSerialization, byte[] secretKey) {
try {
Key key = new AesKey(secretKey);
JsonWebSignature jws = new JsonWebSignature();
jws.setCompactSerialization(jwsCompactSerialization);
jws.setKey(key);
boolean signatureVerified = jws.verifySignature();
return signatureVerified;
} catch (JoseException ex) {
throw new RuntimeException(ex);
}
}
示例9: jwsVerify
import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
private static String jwsVerify(Key key, String jwt) throws Exception {
JsonWebSignature jws = new JsonWebSignature();
jws.setCompactSerialization(jwt);
jws.setKey(key);
jws.setDoKeyValidation(false);
boolean signatureVerified = jws.verifySignature();
System.out.println("JWS signature verification: " + signatureVerified);
System.out.println("JWT Headers: " + jws.getHeaders().getFullHeaderAsJsonString() );
return jws.getPayload();
}
示例10: verifyJWS
import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
private void verifyJWS(Key key, String jwt) {
try {
JsonWebSignature jws = new JsonWebSignature();
jws.setKey(key);
jws.setCompactSerialization(jwt);
jws.setDoKeyValidation(false);
assertTrue(jws.verifySignature());
JwtClaims claims = JwtClaims.parse(jws.getPayload());
assertEquals("abc xyz", claims.getSubject());
assertEquals("[email protected]", claims.getClaimValue("email"));
} catch (Exception e) {
fail();
}
}
示例11: jwsVerificationExample
import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
@Test
public void jwsVerificationExample() throws JoseException
{
//
// An example of signature verification using JSON Web Signature (JWS)
//
// The complete JWS representation, or compact serialization, is string consisting of
// three dot ('.') separated base64url-encoded parts in the form Header.Payload.Signature
String compactSerialization = "eyJhbGciOiJFUzI1NiJ9." +
"VGhpcyBpcyBzb21lIHRleHQgdGhhdCBpcyB0byBiZSBzaWduZWQu." +
"GHiNd8EgKa-2A4yJLHyLCqlwoSxwqv2rzGrvUTxczTYDBeUHUwQRB3P0dp_DALL0jQIDz2vQAT_cnWTIW98W_A";
// Create a new JsonWebSignature
JsonWebSignature jws = new JsonWebSignature();
// Set the compact serialization on the JWS
jws.setCompactSerialization(compactSerialization);
// Set the verification key
// Note that your application will need to determine where/how to get the key
// Here we use an example from the JWS spec
PublicKey publicKey = ExampleEcKeysFromJws.PUBLIC_256;
jws.setKey(publicKey);
// Check the signature
boolean signatureVerified = jws.verifySignature();
// Do something useful with the result of signature verification
System.out.println("JWS Signature is valid: " + signatureVerified);
// Get the payload, or signed content, from the JWS
String payload = jws.getPayload();
// Do something useful with the content
System.out.println("JWS payload: " + payload);
}
示例12: parseResponse
import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
private JSONObject parseResponse() {
JSONParser parser = new JSONParser();
JSONObject responsePayloadJSON = null;
try {
JsonWebSignature responseJWS = new JsonWebSignature();
responseJWS.setCompactSerialization(this.responseToken);
HmacKey key = new HmacKey(Base64.decode(this.useBase64Key));
responseJWS.setKey(key);
responsePayloadJSON = (JSONObject)parser.parse(responseJWS.getPayload());
// workaround for PingID API 4.5 beta
if (responsePayloadJSON.containsKey("responseBody")) {
responsePayloadJSON = (JSONObject)responsePayloadJSON.get("responseBody");
}
} catch (Exception e) {
e.printStackTrace();
}
if (responsePayloadJSON != null) {
this.errorId = (long)responsePayloadJSON.get("errorId");
this.errorMsg = (String)responsePayloadJSON.get("errorMsg");
this.uniqueMsgId = (String)responsePayloadJSON.get("uniqueMsgId");
this.clientData = (String)responsePayloadJSON.get("clientData");
} else {
this.errorId = 501;
this.errorMsg = "Could not parse JWS";
this.uniqueMsgId = "";
this.clientData = "";
this.wasSuccessful = false;
}
return responsePayloadJSON;
}
示例13: getUnverifiedPayloadFromJwsCompactSerialization
import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
@Override
public String getUnverifiedPayloadFromJwsCompactSerialization(String jwsCompactSerialization) {
try {
JsonWebSignature jws = new JsonWebSignature();
jws.setCompactSerialization(jwsCompactSerialization);
String unverifiedPayload = jws.getUnverifiedPayload();
return unverifiedPayload;
} catch (JoseException ex) {
throw new RuntimeException(ex);
}
}
示例14: parseJwksAndVerifyJwsExample
import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
@Test
public void parseJwksAndVerifyJwsExample() throws JoseException
{
//
// An example of signature verification using JSON Web Signature (JWS)
// where the verification key is obtained from a JSON Web Key Set document.
//
// A JSON Web Key (JWK) is a JavaScript Object Notation (JSON) data structure that represents a
// cryptographic key (often but not always a public key). A JSON Web Key Set (JWK Set) document
// is a JSON data structure for representing one or more JSON Web Keys (JWK). A JWK Set might,
// for example, be obtained from an HTTPS endpoint controlled by the signer but this example
// presumes the JWK Set JSONhas already been acquired by some secure/trusted means.
String jsonWebKeySetJson = "{\"keys\":[" +
"{\"kty\":\"EC\",\"use\":\"sig\"," +
"\"kid\":\"the key\"," +
"\"x\":\"amuk6RkDZi-48mKrzgBN_zUZ_9qupIwTZHJjM03qL-4\"," +
"\"y\":\"ZOESj6_dpPiZZR-fJ-XVszQta28Cjgti7JudooQJ0co\",\"crv\":\"P-256\"}," +
"{\"kty\":\"EC\",\"use\":\"sig\"," +
" \"kid\":\"other key\"," +
"\"x\":\"eCNZgiEHUpLaCNgYIcvWzfyBlzlaqEaWbt7RFJ4nIBA\"," +
"\"y\":\"UujFME4pNk-nU4B9h4hsetIeSAzhy8DesBgWppiHKPM\",\"crv\":\"P-256\"}]}";
// The complete JWS representation, or compact serialization, is string consisting of
// three dot ('.') separated base64url-encoded parts in the form Header.Payload.Signature
String compactSerialization = "eyJhbGciOiJFUzI1NiIsImtpZCI6InRoZSBrZXkifQ." +
"UEFZTE9BRCE."+
"Oq-H1lk5G0rl6oyNM3jR5S0-BZQgTlamIKMApq3RX8Hmh2d2XgB4scvsMzGvE-OlEmDY9Oy0YwNGArLpzXWyjw";
// Create a new JsonWebSignature object
JsonWebSignature jws = new JsonWebSignature();
// Set the compact serialization on the JWS
jws.setCompactSerialization(compactSerialization);
// Create a new JsonWebKeySet object with the JWK Set JSON
JsonWebKeySet jsonWebKeySet = new JsonWebKeySet(jsonWebKeySetJson);
// The JWS header contains information indicating which key was used to secure the JWS.
// In this case (as will hopefully often be the case) the JWS Key ID
// corresponds directly to the Key ID in the JWK Set.
// The VerificationJwkSelector looks at Key ID, Key Type, designated use (signatures vs. encryption),
// and the designated algorithm in order to select the appropriate key for verification from
// a set of JWKs.
VerificationJwkSelector jwkSelector = new VerificationJwkSelector();
JsonWebKey jwk = jwkSelector.select(jws, jsonWebKeySet.getJsonWebKeys());
// The verification key on the JWS is the public key from the JWK we pulled from the JWK Set.
jws.setKey(jwk.getKey());
// Check the signature
boolean signatureVerified = jws.verifySignature();
// Do something useful with the result of signature verification
System.out.println("JWS Signature is valid: " + signatureVerified);
// Get the payload, or signed content, from the JWS
String payload = jws.getPayload();
// Do something useful with the content
System.out.println("JWS payload: " + payload);
}
示例15: verifySignedRequestObject
import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
@Test
public void verifySignedRequestObject() throws Exception
{
// OpenID Connect Core 1.0 - draft 15
// 5.1. Passing a Request Object by Value has a JWS JWT with a JWK
String requestObject =
"eyJhbGciOiJSUzI1NiJ9.ew0KICJyZXNwb25zZV90eXBlIjogImNvZGUgaWRfdG9rZW" +
"4iLA0KICJjbGllbnRfaWQiOiAiczZCaGRSa3F0MyIsDQogInJlZGlyZWN0X3VyaSI6I" +
"CJodHRwczovL2NsaWVudC5leGFtcGxlLm9yZy9jYiIsDQogInNjb3BlIjogIm9wZW5p" +
"ZCIsDQogInN0YXRlIjogImFmMGlmanNsZGtqIiwNCiAibm9uY2UiOiAibi0wUzZfV3p" +
"BMk1qIiwNCiAibWF4X2FnZSI6IDg2NDAwLA0KICJjbGFpbXMiOiANCiAgew0KICAgIn" +
"VzZXJpbmZvIjogDQogICAgew0KICAgICAiZ2l2ZW5fbmFtZSI6IHsiZXNzZW50aWFsI" +
"jogdHJ1ZX0sDQogICAgICJuaWNrbmFtZSI6IG51bGwsDQogICAgICJlbWFpbCI6IHsi" +
"ZXNzZW50aWFsIjogdHJ1ZX0sDQogICAgICJlbWFpbF92ZXJpZmllZCI6IHsiZXNzZW5" +
"0aWFsIjogdHJ1ZX0sDQogICAgICJwaWN0dXJlIjogbnVsbA0KICAgIH0sDQogICAiaW" +
"RfdG9rZW4iOiANCiAgICB7DQogICAgICJnZW5kZXIiOiBudWxsLA0KICAgICAiYmlyd" +
"GhkYXRlIjogeyJlc3NlbnRpYWwiOiB0cnVlfSwNCiAgICAgImFjciI6IHsidmFsdWVz" +
"IjogWyIyIl19DQogICAgfQ0KICB9DQp9.bOD4rUiQfzh4QPIs_f_R2GVBhNHcc1p2cQ" +
"TgixB1tsYRs52xW4TO74USgb-nii3RPsLdfoPlsEbJLmtbxG8-TQBHqGAyZxMDPWy3p" +
"hjeRt9ApDRnLQrjYuvsCj6byu9TVaKX9r1KDFGT-HLqUNlUTpYtCyM2B2rLkWM08ufB" +
"q9JBCEzzaLRzjevYEPMaoLAOjb8LPuYOYTBqshRMUxy4Z380-FJ2Lc7VSfSu6HcB2nL" +
"SjiKrrfI35xkRJsaSSmjasMYeDZarYCl7r4o17rFclk5KacYMYgAs-JYFkwab6Dd56Z" +
"rAzakHt9cExMpg04lQIux56C-Qk6dAsB6W6W91AQ";
String jwkJson = "{" +
" \"kty\":\"RSA\"," +
" \"n\":\"y9Lqv4fCp6Ei-u2-ZCKq83YvbFEk6JMs_pSj76eMkddWRuWX2aBKGHAtKlE5P" +
" 7_vn__PCKZWePt3vGkB6ePgzAFu08NmKemwE5bQI0e6kIChtt_6KzT5OaaXDF" +
" I6qCLJmk51Cc4VYFaxgqevMncYrzaW_50mZ1yGSFIQzLYP8bijAHGVjdEFgZa" +
" ZEN9lsn_GdWLaJpHrB3ROlS50E45wxrlg9xMncVb8qDPuXZarvghLL0HzOuYR" +
" adBJVoWZowDNTpKpk2RklZ7QaBO7XDv3uR7s_sf2g-bAjSYxYUGsqkNA9b3xV" +
" W53am_UZZ3tZbFTIh557JICWKHlWj5uzeJXaw\"," +
" \"e\":\"AQAB\"" +
" }";
JsonWebKey jwk = JsonWebKey.Factory.newJwk(jwkJson);
JsonWebSignature jws = new JsonWebSignature();
jws.setCompactSerialization(requestObject);
jws.setKey(jwk.getKey());
assertThat(jws.verifySignature(), is(true));
JwtConsumer jwtConsumer = new JwtConsumerBuilder()
.setVerificationKey(jwk.getKey())
.build();
JwtClaims jwtClaims = jwtConsumer.processToClaims(requestObject);
assertThat("https://client.example.org/cb", equalTo(jwtClaims.getStringClaimValue("redirect_uri")));
}