com.nimbusds.jose.Payload.toString()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(183)

本文整理了Java中com.nimbusds.jose.Payload.toString()方法的一些代码示例,展示了Payload.toString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Payload.toString()方法的具体详情如下:
包路径:com.nimbusds.jose.Payload
类名称:Payload
方法名:toString

Payload.toString介绍

[英]Returns a string representation of this payload.
[中]返回此有效负载的字符串表示形式。

代码示例

代码示例来源:origin: google/data-transfer-project

@Override
 public AuthDataPair decrypt(String encrypted, PrivateKey privateKey) {
  try {
   RSADecrypter decrypter = new RSADecrypter(privateKey);
   JWEObject object = JWEObject.parse(encrypted);
   object.decrypt(decrypter);
   return objectMapper.readValue(object.getPayload().toString(), AuthDataPair.class);
  } catch (IOException | ParseException | JOSEException e) {
   throw new SecurityException("Error decrypting auth tokens", e);
  }
 }
}

代码示例来源:origin: apache/knox

@Override
public String getPayload() {
 Payload payload = jwt.getPayload();
 return payload.toString();
}

代码示例来源:origin: org.apache.knox/gateway-spi

@Override
public String getPayload() {
 Payload payload = jwt.getPayload();
 return payload.toString();
}

代码示例来源:origin: com.nimbusds/nimbus-jose-jwt

/**
 * Returns a signed JSON Web Token (JWT) representation of this
 * payload. Intended for signed then encrypted JWTs.
 *
 * @return The signed JWT representation, {@code null} if the payload
 *         couldn't be converted to a signed JWT.
 */
public SignedJWT toSignedJWT() {
  if (signedJWT != null) {
    return signedJWT;
  }
  try {
    return SignedJWT.parse(toString());
  } catch (ParseException e) {
    return null;
  }
}

代码示例来源:origin: com.nimbusds/nimbus-jose-jwt

/**
 * Returns a JWS object representation of this payload. Intended for
 * signed then encrypted JOSE objects.
 *
 * @return The JWS object representation, {@code null} if the payload
 *         couldn't be converted to a JWS object.
 */
public JWSObject toJWSObject() {
  if (jwsObject != null) {
    return jwsObject;
  }
  try {
    return JWSObject.parse(toString());
  } catch (ParseException e) {
    return null;
  }
}

代码示例来源:origin: com.nimbusds/nimbus-jose-jwt

/**
 * Returns a JSON object representation of this payload.
 *
 * @return The JSON object representation, {@code null} if the payload
 *         couldn't be converted to a JSON object.
 */
public JSONObject toJSONObject() {
  if (jsonObject != null) {
    return jsonObject;
  }
  // Convert
  String s = toString();
  if (s == null) {
    // to string conversion failed
    return null;
  }
  try {
    return JSONObjectUtils.parse(s);
  } catch (ParseException e) {
    // Payload not a JSON object
    return null;
  }
}

代码示例来源:origin: com.nimbusds/nimbus-jose-jwt

/**
 * Returns a byte array representation of this payload.
 *
 * @return The byte array representation.
 */
public byte[] toBytes() {
  if (bytes != null) {
    return bytes;
  }
  // Convert
  if (base64URL != null) {
    return base64URL.decode();
  }
  return stringToByteArray(toString());
}

代码示例来源:origin: com.mastercard.sdk.core/mastercard-sdk-core

/**
 * Decrypt jwe encrypted payload.
 *
 * @param encryptedJwePayload the encryptedJwePayload encrypted payload input.
 * @param privateKey          the private key.
 * @param responseType        the response type.
 * @return payload the decrypted payload json string.
 * @throws SDKConversionException
 */
public static <T> T getJweDecryptedPayload(String encryptedJwePayload, PrivateKey privateKey, Class<? extends T> responseType) throws SDKConversionException {
  if (null == responseType) {
    log.error(ERR_MSG_RESP_TYPE_NOT_NULL);
    throw new SDKConversionException(ERR_MSG_RESP_TYPE_NOT_NULL);
  }
  return responseBodyConverter(getDecryptedPayload(encryptedJwePayload, privateKey).toString(), responseType);
}

代码示例来源:origin: de.adorsys.keycloak/user-secret-adapter-embedded

private String decrypt(String encrypted, byte[] key) {
  try {
    JWEObject jweObject = JWEObject.parse(encrypted);
    jweObject.decrypt(new DirectDecrypter(key));
    return jweObject.getPayload().toString();
  } catch (JOSEException | ParseException e) {
    throw new IllegalStateException(e);
  }
}

代码示例来源:origin: de.adorsys.sts/sts-simple-encryption

String decrypted = jweObject.getPayload().toString();
return Optional.of(decrypted);

代码示例来源:origin: com.mastercard.sdk.core/mastercard-sdk-core

/**
 * Decrypt encrypted payload, verify signature and convert it to response type.
 * @param payload        the payload json string.
 * @param signature        the signature.
 * @param privateKey    the private key.
 * @param publicKey      the public key provided by the masterpass.
 * @param responseType     the response type.
 * @return payload         the decrypted payload json string.
 * @throws SDKValidationException
 */
public static <T> T decryptAndVerify(String payload, String signature, PrivateKey privateKey,
    PublicKey publicKey, Class<? extends T> responseType) {
  if (null == responseType) {
    log.error(ERR_MSG_RESP_TYPE_NOT_NULL);
    throw new SDKValidationException(ERR_MSG_RESP_TYPE_NOT_NULL);
  }
  String decryptedPayload = getDecryptedPayload(payload, privateKey).toString();
  if (!verifySignature(decryptedPayload, signature, publicKey)) {
    log.error("Signature verification failed.");
    throw new SDKValidationException("Signature verification failed.");
  }
  return responseBodyConverter(decryptedPayload, responseType);
}

代码示例来源:origin: panchitoboy/shiro-jwt

public JWTAuthenticationToken createToken(String token) {
  try {
    JWSObject jwsObject = JWSObject.parse(token);
    String decrypted = jwsObject.getPayload().toString();
    
    try (JsonReader jr = Json.createReader(new StringReader(decrypted))) {
      JsonObject object = jr.readObject();
      String userId = object.getString("sub", null);
      return new JWTAuthenticationToken(userId, token);
    }
  } catch (ParseException ex) {
    throw new AuthenticationException(ex);
  }
}

代码示例来源:origin: voxelwind/voxelwind

JsonNode payloadNode = VoxelwindServer.MAPPER.readTree(object.getPayload().toString());
JsonNode ipkNode = payloadNode.get("identityPublicKey");
Verify.verify(ipkNode != null && ipkNode.getNodeType() == JsonNodeType.STRING, "identityPublicKey node is missing in chain");

代码示例来源:origin: hammock-project/hammock

@Override
  public JsonObject process(String jwt) throws JWTException {
    String[] parts = jwt.split("\\.");
    if(parts.length == 3) {
      Base64URL first = new Base64URL(parts[0]);
      Base64URL second = new Base64URL(parts[1]);
      Base64URL third = new Base64URL(parts[2]);
      try {
        String rawJwt = new JWSObject(first, second, third).getPayload().toString();
        return Json.createReader(new StringReader(rawJwt)).readObject();
      }
      catch (ParseException e) {
        throw new JWTException("Unable to parse JWT", e);
      }
    }
    else {
      return null;
    }
  }
}

代码示例来源:origin: org.wso2.carbon.identity.inbound.auth.oauth2/org.wso2.carbon.identity.oauth

jweObject.decrypt(decrypter);
if (jweObject.getPayload() != null && jweObject.getPayload().toString()
    .split(JWT_PART_DELIMITER).length == NUMBER_OF_PARTS_IN_JWS) {
  return jweObject.getPayload().toString();
} else {
  return new PlainJWT((JWTClaimsSet) encryptedJWT.getJWTClaimsSet()).serialize();

代码示例来源:origin: com.atlassian.jwt/jwt-core

@Nonnull
@Override
public Jwt parse(String jwt) throws JwtParseException
{
  JWSObject jwsObject = parseJWSObject(jwt);
  try
  {
    JWTClaimsSet claims = JWTClaimsSet.parse(jwsObject.getPayload().toJSONObject());
    return new SimpleJwt(claims.getIssuer(), claims.getSubject(), jwsObject.getPayload().toString());
  }
  catch (ParseException e)
  {
    throw new JwtParseException(e);
  }
}

代码示例来源:origin: GluuFederation/oxAuth

private boolean testDecryptNimbusJoseJwt(String jwe) {
  try {
    EncryptedJWT encryptedJwt = EncryptedJWT.parse(jwe);
    //EncryptedJWT encryptedJwt = EncryptedJWT.parse(encryptWithGluu());
    //EncryptedJWT encryptedJwt = EncryptedJWT.parse(encryptWithNimbus());
    JWK jwk = JWK.parse(recipientJwkJson);
    RSAPrivateKey rsaPrivateKey = ((RSAKey) jwk).toRSAPrivateKey();
    JWEDecrypter decrypter = new RSADecrypter(rsaPrivateKey);
    decrypter.getJCAContext().setProvider(BouncyCastleProviderSingleton.getInstance());
    encryptedJwt.decrypt(decrypter);
    final String decryptedPayload = new String(Base64Util.base64urldecode(encryptedJwt.getPayload().toString()));
    System.out.println("Nimbusds decrypt succeed: " + decryptedPayload);
    if (decryptedPayload.equals(PAYLOAD)) {
      return true;
    }
  } catch (Exception e) {
    System.out.println("Nimbusds decrypt failed: " + e.getMessage());
    e.printStackTrace();
  }
  return false;
}

代码示例来源:origin: de.adorsys.sts/sts-keymanagement

public String decrypt(String encrypted) throws SecretDecryptionException {
    JWEObject jweObject;
    try {
      jweObject = JWEObject.parse(encrypted);
    } catch (ParseException e) {
      throw new SecretDecryptionException(e);
    }

    String keyID = jweObject.getHeader().getKeyID();
    Key key = keyMapProvider.getKey(keyID);
    if (key == null) {
      throw new IllegalStateException("No suitable key found");
    }

    JWEDecrypter decrypter;
    try {
      decrypter = decrypterFactory.createJWEDecrypter(jweObject.getHeader(), key);
    } catch (JOSEException e) {
      throw new SecretDecryptionException(e);
    }

    try {
      jweObject.decrypt(decrypter);
    } catch (JOSEException e) {
      throw new SecretDecryptionException(e);
    }

    return jweObject.getPayload().toString();
  }
}

代码示例来源:origin: de.adorsys.sts/sts-simple-encryption

@Override
public String decrypt(String encrypted) {
  JWEObject jweObject;
  try {
    jweObject = JWEObject.parse(encrypted);
  } catch (ParseException e) {
    throw new EncryptionException(e);
  }
  String keyID = jweObject.getHeader().getKeyID();
  Key key = keyProvider.getKeyForDecryption(keyID);
  if (key == null) {
    throw new IllegalStateException("No suitable key found");
  }
  JWEDecrypter decrypter;
  try {
    decrypter = decrypterFactory.createJWEDecrypter(jweObject.getHeader(), key);
  } catch (JOSEException e) {
    throw new EncryptionException(e);
  }
  try {
    jweObject.decrypt(decrypter);
  } catch (JOSEException e) {
    throw new EncryptionException(e);
  }
  return jweObject.getPayload().toString();
}

代码示例来源:origin: com.atlassian.jwt/jwt-core

public SimpleUnverifiedJwt parse(String jwt) throws JwtParseException
{
  JWSObject jwsObject = parseJWSObject(jwt);
  try
  {
    JWTClaimsSet claims = JWTClaimsSet.parse(jwsObject.getPayload().toJSONObject());
    return new SimpleUnverifiedJwt(jwsObject.getHeader().getAlgorithm().getName(), claims.getIssuer(), claims.getSubject(), jwsObject.getPayload().toString());
  }
  catch (ParseException e)
  {
    throw new JwtParseException(e);
  }
}

相关文章