Ejemplo n.º 1
0
  public static Payload getPayloadBySessionId(String sessionId, Key key) throws JoseException {

    JsonWebEncryption jwe = new JsonWebEncryption();
    jwe.setKey(key);
    jwe.setCompactSerialization(sessionId);
    System.out.println("Payload: " + jwe.getPayload());
    return getAsObject(jwe.getPayload());
  }
Ejemplo n.º 2
0
 static void main(String args[]) throws JoseException {
   Key key = new AesKey(ByteUtil.randomBytes(16));
   JsonWebEncryption jwe = new JsonWebEncryption();
   jwe.setPayload("Hello World!");
   jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.A128KW);
   jwe.setEncryptionMethodHeaderParameter(
       ContentEncryptionAlgorithmIdentifiers.AES_128_CBC_HMAC_SHA_256);
   jwe.setKey(key);
   String serializedJwe = jwe.getCompactSerialization();
   System.out.println("Serialized Encrypted JWE: " + serializedJwe);
   jwe = new JsonWebEncryption();
   jwe.setKey(key);
   jwe.setCompactSerialization(serializedJwe);
   System.out.println("Payload: " + jwe.getPayload());
 }
Ejemplo n.º 3
0
 public static String getSessionIdByPayload(Payload payload, Key key) throws JoseException {
   // Key key = new AesKey(ByteUtil.randomBytes(16));
   JsonWebEncryption jwe = new JsonWebEncryption();
   jwe.setPayload(getAsJson(payload));
   jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.A128KW);
   jwe.setEncryptionMethodHeaderParameter(
       ContentEncryptionAlgorithmIdentifiers.AES_128_CBC_HMAC_SHA_256);
   jwe.setKey(key);
   String serializedJwe = jwe.getCompactSerialization();
   System.out.println("Seesion crypte :" + serializedJwe);
   return serializedJwe;
 }
  public static void generateWebToken() {
    try {
      key = new AesKey(ByteUtil.randomBytes(16));
      webToken = new JsonWebEncryption();
      webToken.setPayload("Hello David");

      webToken.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.A128KW);
      webToken.setEncryptionMethodHeaderParameter(
          ContentEncryptionAlgorithmIdentifiers.AES_128_CBC_HMAC_SHA_256);
      webToken.setKey(key);
      String encrypted = webToken.getCompactSerialization();

      System.out.println("Hello David : Encrypted " + encrypted);

      webToken = new JsonWebEncryption();
      webToken.setKey(key);
      webToken.setCompactSerialization(encrypted);
      System.out.println("Payload: " + webToken.getPayload());
    } catch (JoseException ex) {
      ex.printStackTrace();
    }
  }