当前位置: 首页>>代码示例>>Java>>正文


Java JsonWebSignature.getPayload方法代码示例

本文整理汇总了Java中org.jose4j.jws.JsonWebSignature.getPayload方法的典型用法代码示例。如果您正苦于以下问题:Java JsonWebSignature.getPayload方法的具体用法?Java JsonWebSignature.getPayload怎么用?Java JsonWebSignature.getPayload使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jose4j.jws.JsonWebSignature的用法示例。


在下文中一共展示了JsonWebSignature.getPayload方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:26,代码来源:EncodingUtils.java

示例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);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:26,代码来源:AbstractCipherExecutor.java

示例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);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:23,代码来源:DefaultCipherExecutor.java

示例4: 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);
    }
}
 
开发者ID:xuchengdong,项目名称:cas4.1.9,代码行数:26,代码来源:AbstractCipherExecutor.java

示例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.
 */
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);
    }
}
 
开发者ID:nano-projects,项目名称:nano-framework,代码行数:23,代码来源:DefaultCipherExecutor.java

示例6: 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();
}
 
开发者ID:gahana,项目名称:edge-jwt-sample,代码行数:13,代码来源:JWTUtil.java

示例7: 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);
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:38,代码来源:ExamplesTest.java

示例8: 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);
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:63,代码来源:ExamplesTest.java


注:本文中的org.jose4j.jws.JsonWebSignature.getPayload方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。