当前位置: 首页>>代码示例>>Java>>正文


Java JsonWebEncryption.setCompactSerialization方法代码示例

本文整理汇总了Java中org.jose4j.jwe.JsonWebEncryption.setCompactSerialization方法的典型用法代码示例。如果您正苦于以下问题:Java JsonWebEncryption.setCompactSerialization方法的具体用法?Java JsonWebEncryption.setCompactSerialization怎么用?Java JsonWebEncryption.setCompactSerialization使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jose4j.jwe.JsonWebEncryption的用法示例。


在下文中一共展示了JsonWebEncryption.setCompactSerialization方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: decryptJWT

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
/**
 * Decrypt the otp received via mail
 */
@Override
public String decryptJWT(String token) {
  JsonWebEncryption jwe = new JsonWebEncryption();
  Key key = new AesKey(ConfigUtil.get(JWTKEY).getBytes());
  jwe.setKey(key);
  jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.A128KW);
  jwe.setEncryptionMethodHeaderParameter(
      ContentEncryptionAlgorithmIdentifiers.AES_128_CBC_HMAC_SHA_256);
  try {
    jwe.setCompactSerialization(token);
    return jwe.getPayload();
  } catch (JoseException e) {
    xLogger.warn("Unable to get the jwt service: {0}", e.getMessage());
  }
  jwe.setKey(key);
  return null;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:21,代码来源:AuthenticationServiceImpl.java

示例2: verifyJWE

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
private void verifyJWE(Key key, String keyAlgo, String jweAlgo, String jwt) {
	try {
	    JsonWebEncryption jwe = new JsonWebEncryption();
	    jwe.setAlgorithmConstraints(
	    	new AlgorithmConstraints(
	    		ConstraintType.WHITELIST, 
	    		ALGORITHMS.get(keyAlgo)));
	    jwe.setContentEncryptionAlgorithmConstraints(
	    	new AlgorithmConstraints(
	    		ConstraintType.WHITELIST, 
	    		ALGORITHMS.get(jweAlgo)));
	    jwe.setCompactSerialization(jwt);
	    jwe.setKey(key);
		JwtClaims claims = JwtClaims.parse(jwe.getPlaintextString());
		assertEquals("abc xyz", claims.getSubject());
		assertEquals("[email protected]", claims.getClaimValue("email"));
	} catch (Exception e) {
		fail();
	}
}
 
开发者ID:gahana,项目名称:edge-jwt-sample,代码行数:21,代码来源:JWTGeneratorTest.java

示例3: getHeaders

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
@Override
public Map<String, String> getHeaders(String data) throws JWEFailure {
    try {
        String headerSegment = data.split("\\.")[0];
        JsonWebEncryption jwe = new JsonWebEncryption();
        jwe.setCompactSerialization(data);
        String headersJSON = jwe.getHeaders().getFullHeaderAsJsonString();
        Map<String, Object> objectMap = JsonUtil.parseJson(headersJSON);
        Map<String, String> headers = new LinkedHashMap<>(objectMap.size());
        for (Map.Entry<String, Object> entry : objectMap.entrySet()) {
            headers.put(entry.getKey(), String.valueOf(entry.getValue()));
        }
        return headers;
    } catch (Exception e) {
        throw new JWEFailure("Unable to parse data for JWE Header!", e);
    }
}
 
开发者ID:iovation,项目名称:launchkey-java,代码行数:18,代码来源:Jose4jJWEService.java

示例4: decryptValue

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
/**
 * Decrypt value based on the key created during afterPropertiesSet.
 *
 * @param value the value
 * @return the decrypted value
 */
private String decryptValue(@NotNull final String value) {
    try {
        final JsonWebEncryption jwe = new JsonWebEncryption();
        jwe.setKey(this.secretKeyEncryptionKey);
        jwe.setCompactSerialization(value);
        logger.debug("Decrypting value...");
        return jwe.getPayload();
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:18,代码来源:BaseStringCipherExecutor.java

示例5: decryptValue

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
/**
 * Decrypt value based on the key created during init.
 *
 * @param value the value
 * @return the decrypted value
 */
private String decryptValue(@NotNull final String value) {
    try {
        final JsonWebEncryption jwe = new JsonWebEncryption();
        jwe.setKey(this.secretKeyEncryptionKey);
        jwe.setCompactSerialization(value);
        logger.debug("Decrypting value...");
        return jwe.getPayload();
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:18,代码来源:DefaultCipherExecutor.java

示例6: decryptValue

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
/**
 * Decrypt value based on the key created during afterPropertiesSet.
 *
 * @param value the value
 * @return the decrypted value
 */
private String decryptValue(final String value) {
    try {
        final JsonWebEncryption jwe = new JsonWebEncryption();
        jwe.setKey(this.secretKeyEncryptionKey);
        jwe.setCompactSerialization(value);
        LOGGER.debug("Decrypting value...");
        return jwe.getPayload();
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:18,代码来源:BaseStringCipherExecutor.java

示例7: aesEncryptDecrypt128

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
@Test
public void aesEncryptDecrypt128() throws Exception {

    String keyText = "iue98623diDEs096";
    String data = "I am marico";
    Key key = new AesKey(keyText.getBytes());

    //加密
    JsonWebEncryption jwe = new JsonWebEncryption();
    jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.A128KW);
    jwe.setEncryptionMethodHeaderParameter(ContentEncryptionAlgorithmIdentifiers.AES_128_CBC_HMAC_SHA_256);
    jwe.setKey(key);
    jwe.setPayload(data);

    String idToken = jwe.getCompactSerialization();
    assertNotNull(idToken);
    System.out.println(data + " idToken: " + idToken);

    //解密
    JsonWebEncryption jwe2 = new JsonWebEncryption();
    jwe2.setKey(key);
    jwe2.setCompactSerialization(idToken);

    final String payload = jwe2.getPayload();
    assertNotNull(payload);
    assertEquals(payload, data);

}
 
开发者ID:monkeyk,项目名称:oauth2-shiro,代码行数:29,代码来源:Jose4JTest.java

示例8: aesEncryptDecrypt256

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
@Test
public void aesEncryptDecrypt256() throws Exception {

    String keyText = "[email protected](*JKse09";
    String data = "I am marico";
    Key key = new AesKey(keyText.getBytes());

    //加密
    JsonWebEncryption jwe = new JsonWebEncryption();
    jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.A256KW);
    jwe.setEncryptionMethodHeaderParameter(ContentEncryptionAlgorithmIdentifiers.AES_256_CBC_HMAC_SHA_512);
    jwe.setKey(key);
    jwe.setPayload(data);

    String idToken = jwe.getCompactSerialization();
    assertNotNull(idToken);
    System.out.println(data + " idToken: " + idToken);

    //解密
    JsonWebEncryption jwe2 = new JsonWebEncryption();
    jwe2.setKey(key);
    jwe2.setCompactSerialization(idToken);

    final String payload = jwe2.getPayload();
    assertNotNull(payload);
    assertEquals(payload, data);

}
 
开发者ID:monkeyk,项目名称:oauth2-shiro,代码行数:29,代码来源:Jose4JTest.java

示例9: jweDecrypt

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
private static String jweDecrypt(Key key, String jwt) throws Exception {
    JsonWebEncryption jwe = new JsonWebEncryption();
    jwe.setAlgorithmConstraints(
    	new AlgorithmConstraints(
    		ConstraintType.WHITELIST, 
    		KeyManagementAlgorithmIdentifiers.RSA_OAEP));
    jwe.setContentEncryptionAlgorithmConstraints(
    	new AlgorithmConstraints(
    		ConstraintType.WHITELIST, 
    		ContentEncryptionAlgorithmIdentifiers.AES_256_CBC_HMAC_SHA_512));
    jwe.setCompactSerialization(jwt);
    jwe.setKey(key);
    return jwe.getPlaintextString();
}
 
开发者ID:gahana,项目名称:edge-jwt-sample,代码行数:15,代码来源:JWTUtil.java

示例10: decryptValue

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
/**
 * Decrypt value based on the key created during init.
 *
 * @param value the value
 * @return the decrypted value
 */
private String decryptValue(@NotNull final String value) {
    try {
        final JsonWebEncryption jwe = new JsonWebEncryption();
        jwe.setKey(this.secretKeyEncryptionKey);
        jwe.setCompactSerialization(value);
        LOGGER.debug("Decrypting value...");
        return jwe.getPayload();
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:nano-projects,项目名称:nano-framework,代码行数:18,代码来源:DefaultCipherExecutor.java

示例11: parseToken

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
@Nullable
public static User parseToken(@NotNull JsonWebEncryption jwe, @NotNull String token, int tokenEnsureTime) {
  try {
    jwe.setCompactSerialization(token);
    final JwtClaims claims = JwtClaims.parse(jwe.getPayload());
    final NumericDate now = NumericDate.now();
    final NumericDate expire = NumericDate.fromMilliseconds(now.getValueInMillis());
    if (tokenEnsureTime > 0) {
      expire.addSeconds(tokenEnsureTime);
    }
    if (claims.getExpirationTime() == null || claims.getExpirationTime().isBefore(expire)) {
      return null;
    }
    if (claims.getNotBefore() == null || claims.getNotBefore().isAfter(now)) {
      return null;
    }
    if (claims.getSubject() == null) {
      return User.getAnonymous();
    }
    return User.create(
        claims.getSubject(),
        claims.getClaimValue("name", String.class),
        claims.getClaimValue("email", String.class),
        claims.getClaimValue("external", String.class)
    );
  } catch (JoseException | MalformedClaimException | InvalidJwtException e) {
    log.warn("Token parsing error: " + e.getMessage());
    return null;
  }
}
 
开发者ID:bozaro,项目名称:git-as-svn,代码行数:31,代码来源:TokenHelper.java

示例12: decrypt

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
@Override
public String decrypt(String data, PrivateKey privateKey) throws JWEFailure {
    String decrypted;
    JsonWebEncryption jwe = new JsonWebEncryption();
    jwe.setKey(privateKey);
    try {
        jwe.setCompactSerialization(data);
        decrypted = jwe.getPlaintextString();
    } catch (JoseException e) {
        throw new JWEFailure("An error occurred attempting to decrypt a JWE", e);
    }
    return decrypted;
}
 
开发者ID:iovation,项目名称:launchkey-java,代码行数:14,代码来源:Jose4jJWEService.java

示例13: jweRoundTripExample

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
@Test
public void jweRoundTripExample() throws JoseException
{
    //
    // An example showing the use of JSON Web Encryption (JWE) to encrypt and then decrypt some content
    // using a symmetric key and direct encryption.
    //

    // The content to be encrypted
    String message = "Well, as of this moment, they're on DOUBLE SECRET PROBATION!";

    // The shared secret or shared symmetric key represented as a octet sequence JSON Web Key (JWK)
    String jwkJson = "{\"kty\":\"oct\",\"k\":\"Fdh9u8rINxfivbrianbbVT1u232VQBZYKx1HGAGPt2I\"}";
    JsonWebKey jwk = JsonWebKey.Factory.newJwk(jwkJson);

    // Create a new Json Web Encryption object
    JsonWebEncryption senderJwe = new JsonWebEncryption();

    // The plaintext of the JWE is the message that we want to encrypt.
    senderJwe.setPlaintext(message);

    // Set the "alg" header, which indicates the key management mode for this JWE.
    // In this example we are using the direct key management mode, which means
    // the given key will be used directly as the content encryption key.
    senderJwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.DIRECT);

    // Set the "enc" header, which indicates the content encryption algorithm to be used.
    // This example is using AES_128_CBC_HMAC_SHA_256 which is a composition of AES CBC
    // and HMAC SHA2 that provides authenticated encryption.
    senderJwe.setEncryptionMethodHeaderParameter(ContentEncryptionAlgorithmIdentifiers.AES_128_CBC_HMAC_SHA_256);

    // Set the key on the JWE. In this case, using direct mode, the key will used directly as
    // the content encryption key. AES_128_CBC_HMAC_SHA_256, which is being used to encrypt the
    // content requires a 256 bit key.
    senderJwe.setKey(jwk.getKey());

    // Produce the JWE compact serialization, which is where the actual encryption is done.
    // The JWE compact serialization consists of five base64url encoded parts
    // combined with a dot ('.') character in the general format of
    // <header>.<encrypted key>.<initialization vector>.<ciphertext>.<authentication tag>
    // Direct encryption doesn't use an encrypted key so that field will be an empty string
    // in this case.
    String compactSerialization = senderJwe.getCompactSerialization();

    // Do something with the JWE. Like send it to some other party over the clouds
    // and through the interwebs.
    System.out.println("JWE compact serialization: " + compactSerialization);

    // That other party, the receiver, can then use JsonWebEncryption to decrypt the message.
    JsonWebEncryption receiverJwe = new JsonWebEncryption();

    // Set the compact serialization on new Json Web Encryption object
    receiverJwe.setCompactSerialization(compactSerialization);

    // Symmetric encryption, like we are doing here, requires that both parties have the same key.
    // The key will have had to have been securely exchanged out-of-band somehow.
    receiverJwe.setKey(jwk.getKey());

    // Get the message that was encrypted in the JWE. This step performs the actual decryption steps.
    String plaintext = receiverJwe.getPlaintextString();

    // And do whatever you need to do with the clear text message.
    System.out.println("plaintext: " + plaintext);
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:65,代码来源:ExamplesTest.java


注:本文中的org.jose4j.jwe.JsonWebEncryption.setCompactSerialization方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。