Package com.nimbusds.jose

Examples of com.nimbusds.jose.Payload


    // Create JWS header with HS256 algorithm
    JWSHeader header = new JWSHeader(JWSAlgorithm.HS256);
    header.setContentType("text/plain");

    // Create JWS object
    JWSObject jwsObject = new JWSObject(header, new Payload(jwtClaims.toJSONObject()));

    // Create HMAC signer
    JWSSigner signer = new MACSigner(SHARED_KEY.getBytes());

    try {
View Full Code Here


  public void testWithA128GCM()
    throws Exception {

    JWEHeader header = new JWEHeader(JWEAlgorithm.RSA_OAEP, EncryptionMethod.A128GCM);
    Payload payload = new Payload("Hello world!");

    JWEObject jweObject = new JWEObject(header, payload);

    assertEquals("State check", JWEObject.State.UNENCRYPTED, jweObject.getState());

    JWEEncrypter encrypter = new RSAEncrypter(publicKey);

    jweObject.encrypt(encrypter);

    assertEquals("State check", JWEObject.State.ENCRYPTED, jweObject.getState());

    String jweString = jweObject.serialize();

    jweObject = JWEObject.parse(jweString);

    JWEDecrypter decrypter = new RSADecrypter(privateKey);

    assertEquals(privateKey, ((RSADecrypter)decrypter).getPrivateKey());

    jweObject.decrypt(decrypter);

    assertEquals("State check", JWEObject.State.DECRYPTED, jweObject.getState());

    payload = jweObject.getPayload();

    assertEquals("Hello world!", payload.toString());
  }
View Full Code Here

  public void testwithSHA256AndA128GCM()
    throws Exception {

    JWEHeader header = new JWEHeader(JWEAlgorithm.RSA_OAEP_256, EncryptionMethod.A128GCM);
    Payload payload = new Payload("Hello world!");

    JWEObject jweObject = new JWEObject(header, payload);

    assertEquals("State check", JWEObject.State.UNENCRYPTED, jweObject.getState());

    JWEEncrypter encrypter = new RSAEncrypter(publicKey);
    encrypter.setKeyEncryptionProvider(BouncyCastleProviderSingleton.getInstance());

    jweObject.encrypt(encrypter);

    assertEquals("State check", JWEObject.State.ENCRYPTED, jweObject.getState());

    String jweString = jweObject.serialize();

    jweObject = JWEObject.parse(jweString);

    JWEDecrypter decrypter = new RSADecrypter(privateKey);
    decrypter.setKeyEncryptionProvider(BouncyCastleProviderSingleton.getInstance());

    assertEquals(privateKey, ((RSADecrypter)decrypter).getPrivateKey());

    jweObject.decrypt(decrypter);

    assertEquals("State check", JWEObject.State.DECRYPTED, jweObject.getState());

    payload = jweObject.getPayload();

    assertEquals("Hello world!", payload.toString());
  }
View Full Code Here

   *
   * @param claimsSet The JWT claims set. Must not be {@code null}.
   */
  public PlainJWT(final ReadOnlyJWTClaimsSet claimsSet) {

    super(new Payload(claimsSet.toJSONObject()));
  }
View Full Code Here

   * @param header    The plain header. Must not be {@code null}.
   * @param claimsSet The JWT claims set. Must not be {@code null}.
   */
  public PlainJWT(final PlainHeader header, final ReadOnlyJWTClaimsSet claimsSet) {

    super(header, new Payload(claimsSet.toJSONObject()));
  }
View Full Code Here

    // Create HMAC signer
    JWSSigner signer = new MACSigner(sharedSecret);

    // Prepare JWS object with "Hello, world!" payload
    JWSObject jwsObject = new JWSObject(new JWSHeader(JWSAlgorithm.HS256), new Payload("Hello, world!"));

    // Apply the HMAC
    jwsObject.sign(signer);

    assertTrue(jwsObject.getState().equals(JWSObject.State.SIGNED));
View Full Code Here

    // Create RSA-signer with the private key
    JWSSigner signer = new RSASSASigner(privateKey);

    // Prepare JWS object with simple string as payload
    JWSObject jwsObject = new JWSObject(new JWSHeader(JWSAlgorithm.RS256), new Payload("In RSA we trust!"));

    // Compute the RSA signature
    jwsObject.sign(signer);

    assertTrue(jwsObject.getState().equals(JWSObject.State.SIGNED));
View Full Code Here

    KeyPair keyPair = keyGen.genKeyPair();
    RSAPublicKey rsaPublicKey = (RSAPublicKey)keyPair.getPublic();
    RSAPrivateKey rsaPrivateKey = (RSAPrivateKey)keyPair.getPrivate();

    // Create signer from raw Java RSA key
    JWSObject jwsObject1 = new JWSObject(new JWSHeader(JWSAlgorithm.RS256), new Payload("test123"));
    JWSSigner signer = new RSASSASigner(rsaPrivateKey);
    jwsObject1.sign(signer);
    Base64URL sig1 = jwsObject1.getSignature();

    // Create signer from JWK representation
    RSAKey rsaJWK = new RSAKey.Builder(rsaPublicKey).privateKey(rsaPrivateKey).build();

    JWSObject jwsObject2 = new JWSObject(new JWSHeader(JWSAlgorithm.RS256), new Payload("test123"));
    signer = new RSASSASigner(rsaJWK.toRSAPrivateKey());
    jwsObject2.sign(signer);
    Base64URL sig2 = jwsObject2.getSignature();

    assertTrue("Signature comparison", sig1.equals(sig2));
View Full Code Here

    JWSHeader header = new JWSHeader.Builder(alg).
      contentType("text/plain").
      build();

    return new JWSObject(header, new Payload("Hello world!"));
  }
View Full Code Here

    KeyPair keyPair = createECKeyPair(EC512SPEC);
    ECPublicKey publicKey = (ECPublicKey) keyPair.getPublic();
    ECPrivateKey privateKey = (ECPrivateKey) keyPair.getPrivate();

    JWSObject jwsObject = new JWSObject(header, new Payload("Hello world!"));

    JWSSigner signer = new ECDSASigner(privateKey.getS());

    jwsObject.sign(signer);
View Full Code Here

TOP

Related Classes of com.nimbusds.jose.Payload

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.