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


Java JsonWebSignature.setKey方法代码示例

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


在下文中一共展示了JsonWebSignature.setKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createSignedTokenFromClaims

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
/**
 * Create a RSA256 signed token from given claims and RSA jwk.
 * 
 * @param JwtClaims claims
 * @param RsaJsonWebKey rsaJsonWebKey
 * @return String
 * @throws JoseException
 */
private String createSignedTokenFromClaims(JwtClaims claims, RsaJsonWebKey rsaJsonWebKey) throws JoseException {

  // A JWT is a JWS and/or a JWE with JSON claims as the payload.
  // In this example it is a JWS so we create a JsonWebSignature object.
  JsonWebSignature jws = new JsonWebSignature();

  // The payload of the JWS is JSON content of the JWT Claims
  jws.setPayload(claims.toJson());

  // The JWT is signed using the private key
  jws.setKey(rsaJsonWebKey.getPrivateKey());

  // Set the signature algorithm on the JWT/JWS that will integrity protect the claims
  jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.RSA_USING_SHA256);

  return jws.getCompactSerialization();
}
 
开发者ID:Staffbase,项目名称:plugins-sdk-java,代码行数:26,代码来源:SSOFacadeTest.java

示例2: createUnsupportedSignedTokenFromClaims

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
/**
 * Create a RSA384 signed token from given claims and RSA jwk.
 * 
 * @param JwtClaims claims
 * @param RsaJsonWebKey rsaJsonWebKey
 * @return String
 * @throws JoseException
 */
private String createUnsupportedSignedTokenFromClaims(JwtClaims claims, RsaJsonWebKey rsaJsonWebKey) throws JoseException {

  // A JWT is a JWS and/or a JWE with JSON claims as the payload.
  // In this example it is a JWS so we create a JsonWebSignature object.
  JsonWebSignature jws = new JsonWebSignature();

  // The payload of the JWS is JSON content of the JWT Claims
  jws.setPayload(claims.toJson());

  // The JWT is signed using the private key
  jws.setKey(rsaJsonWebKey.getPrivateKey());

  // Set the signature algorithm on the JWT/JWS that will integrity protect the claims
  jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.RSA_USING_SHA384);    

  return jws.getCompactSerialization();
}
 
开发者ID:Staffbase,项目名称:plugins-sdk-java,代码行数:26,代码来源:SSOFacadeTest.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.
 */
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

示例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.
 */
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

示例5: prepareJsonWebSignatureForIdTokenSigning

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
private void prepareJsonWebSignatureForIdTokenSigning(final OidcRegisteredService svc, final JsonWebSignature jws,
                                                      final RsaJsonWebKey jsonWebKey) {
    LOGGER.debug("Service [{}] is set to sign id tokens", svc);

    jws.setKey(jsonWebKey.getPrivateKey());
    jws.setAlgorithmConstraints(AlgorithmConstraints.DISALLOW_NONE);
    if (StringUtils.isBlank(jsonWebKey.getKeyId())) {
        jws.setKeyIdHeaderValue(UUID.randomUUID().toString());
    } else {
        jws.setKeyIdHeaderValue(jsonWebKey.getKeyId());
    }
    LOGGER.debug("Signing id token with key id header value [{}]", jws.getKeyIdHeaderValue());
    jws.setAlgorithmHeaderValue(getJsonWebKeySigningAlgorithm());

    LOGGER.debug("Signing id token with algorithm [{}]", jws.getAlgorithmHeaderValue());
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:17,代码来源:OidcIdTokenSigningAndEncryptionService.java

示例6: sign

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public String sign(final JwtClaims claims) {

    try {
        final RsaJsonWebKey aSigningKey = cachedDataProvider.getASigningKey();
        final JsonWebSignature jws = new JsonWebSignature();
        jws.setPayload(claims.toJson());
        jws.setKeyIdHeaderValue(aSigningKey.getKeyId());
        jws.setKey(aSigningKey.getPrivateKey());
        jws.setAlgorithmHeaderValue(aSigningKey.getAlgorithm());
        jws.sign();
        return jws.getCompactSerialization();
    } catch (final JoseException e) {
        throw new InternalServerErrorException(e);
    }
}
 
开发者ID:trajano,项目名称:app-ms,代码行数:20,代码来源:JcaCryptoOps.java

示例7: generateToken

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
public String generateToken(String subject) {
    final JwtClaims claims = new JwtClaims();
    claims.setSubject(subject);
    claims.setExpirationTimeMinutesInTheFuture(TOKEN_EXPIRATION_IN_MINUTES);

    final JsonWebSignature jws = new JsonWebSignature();
    jws.setPayload(claims.toJson());
    jws.setAlgorithmHeaderValue(HMAC_SHA256);
    jws.setKey(new HmacKey(tokenSecret));
    jws.setDoKeyValidation(false); //relaxes hmac key length restrictions

    try {
        return jws.getCompactSerialization();
    } catch (JoseException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:jtanza,项目名称:rufus,代码行数:18,代码来源:TokenGenerator.java

示例8: 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;
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:22,代码来源:DefaultAuthTokenVerifier.java

示例9: generateJwt

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
private static String generateJwt(RsaJsonWebKey jwk, Optional<String> keyId)
    throws JoseException {
  JwtClaims claims = new JwtClaims();
  claims.setIssuer("Issuer");
  claims.setAudience("Audience");

  JsonWebSignature jws = new JsonWebSignature();
  jws.setPayload(claims.toJson());
  jws.setKey(jwk.getPrivateKey());
  jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.RSA_USING_SHA256);

  if (keyId.isPresent()) {
    jws.setKeyIdHeaderValue(keyId.get());
  }

  return jws.getCompactSerialization();
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:18,代码来源:DefaultAuthTokenVerifierTest.java

示例10: createToken

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
private static String createToken(Key key, JsonObject jsonClaims) {

        JwtClaims claims = new JwtClaims();
        claims.setSubject(jsonClaims.toString());
        claims.setIssuedAtToNow();
        claims.setExpirationTime(NumericDate.fromSeconds(NumericDate.now().getValue() + JWT_TOKEN_EXPIRES_TIME));

        JsonWebSignature jws = new JsonWebSignature();
        jws.setDoKeyValidation(false);
        jws.setPayload(claims.toJson());
        jws.setKey(key);
        jws.setAlgorithmHeaderValue(ALG);

        try {
            return jws.getCompactSerialization();
        } catch (JoseException ex) {
            LOGGER.log(Level.SEVERE, null, ex);
        }

        return null;
    }
 
开发者ID:polarsys,项目名称:eplmp,代码行数:22,代码来源:JWTokenFactory.java

示例11: 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

示例12: attemptAll

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
private Key attemptAll(JsonWebSignature jws) throws UnresolvableKeyException
{
    for (X509Certificate certificate : x5tMap.values())
    {
        PublicKey publicKey = certificate.getPublicKey();
        jws.setKey(publicKey);

        try
        {
            if (jws.verifySignature())
            {
                return publicKey;
            }
        }
        catch (JoseException e)
        {
            log.debug("Verify signature didn't work: {}", ExceptionHelp.toStringWithCauses(e));
        }
    }
    StringBuilder sb = new StringBuilder();
    sb.append("Unable to verify the signature with any of the provided keys - SHA-1 thumbs of provided certificates: ");
    sb.append(x5tMap.keySet());
    sb.append(".");
    throw new UnresolvableKeyException(sb.toString());
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:26,代码来源:X509VerificationKeyResolver.java

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

示例14: generateJWT

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
/**
 * Generates a JWT as String representation.
 * Encodes the id and the role of the user as "userId" and "userRole" in the claims of the jwt
 *
 * @param user
 *         The user to generate the JWT from.
 * @return The string representation of the jwt.
 * @throws JoseException
 *         If the Jose library failed to create a JWT token.
 */
public static String generateJWT(User user) throws JoseException {
    // generate claims with user data
    JwtClaims claims = new JwtClaims();
    claims.setIssuer("ALEX");
    claims.setGeneratedJwtId();
    claims.setClaim("id", user.getId());
    claims.setClaim("role", user.getRole());
    claims.setClaim("email", user.getEmail());

    // create signature
    JsonWebSignature jws = new JsonWebSignature();
    jws.setPayload(claims.toJson());
    jws.setKey(getKey().getPrivateKey());
    jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.RSA_USING_SHA256);

    // return signed jwt
    return jws.getCompactSerialization();
}
 
开发者ID:LearnLib,项目名称:alex,代码行数:29,代码来源:JWTHelper.java

示例15: createExternalAccountBinding

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
/**
 * Creates a JSON structure for external account binding.
 *
 * @param kid
 *            Key Identifier provided by the CA
 * @param accountKey
 *            {@link PublicKey} of the account to register
 * @param macKey
 *            {@link SecretKey} to sign the key identifier with
 * @param resource
 *            "newAccount" resource URL
 * @return Created JSON structure
 */
private Map<String, Object> createExternalAccountBinding(String kid,
            PublicKey accountKey, SecretKey macKey, URL resource)
            throws AcmeException {
    try {
        PublicJsonWebKey keyJwk = PublicJsonWebKey.Factory.newPublicJwk(accountKey);

        JsonWebSignature innerJws = new JsonWebSignature();
        innerJws.setPayload(keyJwk.toJson());
        innerJws.getHeaders().setObjectHeaderValue("url", resource);
        innerJws.getHeaders().setObjectHeaderValue("kid", kid);
        innerJws.setAlgorithmHeaderValue(macKeyAlgorithm(macKey));
        innerJws.setKey(macKey);
        innerJws.setDoKeyValidation(false);
        innerJws.sign();

        JSONBuilder outerClaim = new JSONBuilder();
        outerClaim.put("protected", innerJws.getHeaders().getEncodedHeader());
        outerClaim.put("signature", innerJws.getEncodedSignature());
        outerClaim.put("payload", innerJws.getEncodedPayload());
        return outerClaim.toMap();
    } catch (JoseException ex) {
        throw new AcmeException("Could not create external account binding", ex);
    }
}
 
开发者ID:shred,项目名称:acme4j,代码行数:38,代码来源:AccountBuilder.java


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