Esempio n. 1
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;
 }
Esempio 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());
 }
  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();
    }
  }