Package com.nimbusds.jose

Examples of com.nimbusds.jose.JWEHeader



  public void testWithA256GCM()
    throws Exception {

    JWEHeader header = new JWEHeader(JWEAlgorithm.RSA_OAEP, EncryptionMethod.A256GCM);
    Payload payload = new Payload("I think therefore I am.");

    JWEObject jweObject = new JWEObject(header, payload);

    assertEquals("State check", JWEObject.State.UNENCRYPTED, jweObject.getState());
View Full Code Here


      throw new JOSEException("Unsupported JWE algorithm, must be A128KW, A192KW, A256KW, A128GCMKW, A192GCMKW orA256GCMKW");
    }

    // We need to work on the header
    JWEHeader modifiableHeader;

    switch (algFamily) {

      case AESKW:
        encryptedKey = Base64URL.encode(AESKW.encryptCEK(cek, kek));
        modifiableHeader = header; // simply copy ref
        break;

      case AESGCMKW:
        keyIV = AESGCM.generateIV(randomGen);
        authCiphCEK = AESGCMKW.encryptCEK(cek, keyIV, kek, keyEncryptionProvider);
        encryptedKey = Base64URL.encode(authCiphCEK.getCipherText());

        // Add iv and tag to the header
        modifiableHeader = new JWEHeader.Builder(header).
          iv(Base64URL.encode(keyIV)).
          authTag(Base64URL.encode(authCiphCEK.getAuthenticationTag())).
          build();
        break;

      default:
        // This should never happen
        throw new JOSEException("Unsupported JWE algorithm, must be A128KW, A192KW, A256KW, A128GCMKW, A192GCMKW orA256GCMKW");
    }

    // Apply compression if instructed
    byte[] plainText = DeflateHelper.applyCompression(modifiableHeader, bytes);

    // Compose the AAD
    byte[] aad = StringUtils.toByteArray(modifiableHeader.toBase64URL().toString());

    // Encrypt the plain text according to the JWE enc
    byte[] iv;
    AuthenticatedCipherText authCipherText;
View Full Code Here

    String jti = UUID.randomUUID().toString();
    jwtClaims.setJWTID(jti);


    // Request JWT encrypted with RSA-OAEP and 128-bit AES/GCM
    JWEHeader header = new JWEHeader(JWEAlgorithm.RSA_OAEP, EncryptionMethod.A128GCM);


    // Create the encrypted JWT object
    EncryptedJWT jwt = new EncryptedJWT(header, jwtClaims);
View Full Code Here

    String jti = UUID.randomUUID().toString();
    jwtClaims.setJWTID(jti);


    // Request JWT encrypted with RSA-OAEP and 128-bit AES/GCM
    JWEHeader header = new JWEHeader(JWEAlgorithm.RSA_OAEP, EncryptionMethod.A128GCM);


    // Create the encrypted JWT object
    EncryptedJWT jwt = new EncryptedJWT(header, jwtClaims);
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());
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());
View Full Code Here


  public void testWithA192GCM()
    throws Exception {

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

    JWEObject jweObject = new JWEObject(header, payload);

    assertEquals("State check", JWEObject.State.UNENCRYPTED, jweObject.getState());
View Full Code Here


  public void testWithA256GCM()
    throws Exception {

    JWEHeader header = new JWEHeader(JWEAlgorithm.RSA_OAEP, EncryptionMethod.A256GCM);
    Payload payload = new Payload("I think therefore I am.");

    JWEObject jweObject = new JWEObject(header, payload);

    assertEquals("State check", JWEObject.State.UNENCRYPTED, jweObject.getState());
View Full Code Here

TOP

Related Classes of com.nimbusds.jose.JWEHeader

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.