本文整理汇总了Java中org.jose4j.jwe.KeyManagementAlgorithmIdentifiers类的典型用法代码示例。如果您正苦于以下问题:Java KeyManagementAlgorithmIdentifiers类的具体用法?Java KeyManagementAlgorithmIdentifiers怎么用?Java KeyManagementAlgorithmIdentifiers使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
KeyManagementAlgorithmIdentifiers类属于org.jose4j.jwe包,在下文中一共展示了KeyManagementAlgorithmIdentifiers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createJWT
import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的package包/类
/**
* Encrypt the otp to be send via mail
*/
@Override
public String createJWT(String userid, long ttlMillis) {
Key key = new AesKey(ConfigUtil.get(JWTKEY).getBytes());
JsonWebEncryption jwe = new JsonWebEncryption();
jwe.setKey(key);
jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.A128KW);
jwe.setEncryptionMethodHeaderParameter(
ContentEncryptionAlgorithmIdentifiers.AES_128_CBC_HMAC_SHA_256);
jwe.setPayload(userid + "&&" + ttlMillis);
try {
return jwe.getCompactSerialization();
} catch (JoseException e) {
xLogger.warn("Unable to get the jwt service: {0}", e.getMessage());
}
return null;
}
示例2: encryptValue
import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的package包/类
/**
* Encrypt the value based on the seed array whose length was given during afterPropertiesSet,
* and the key and content encryption ids.
*
* @param value the value
* @return the encoded value
*/
private String encryptValue(final Serializable value) {
try {
final JsonWebEncryption jwe = new JsonWebEncryption();
jwe.setPayload(serializeValue(value));
jwe.enableDefaultCompression();
jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.DIRECT);
jwe.setEncryptionMethodHeaderParameter(this.contentEncryptionAlgorithmIdentifier);
jwe.setKey(this.secretKeyEncryptionKey);
LOGGER.debug("Encrypting via [{}]", this.contentEncryptionAlgorithmIdentifier);
return jwe.getCompactSerialization();
} catch (final Exception e) {
throw new RuntimeException("Ensure that you have installed JCE Unlimited Strength Jurisdiction Policy Files. "
+ e.getMessage(), e);
}
}
示例3: decryptJWT
import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的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;
}
示例4: testNpeWithNonExtractableKeyDataDirect
import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的package包/类
public void testNpeWithNonExtractableKeyDataDirect() throws Exception
{
littleJweRoundTrip(KeyManagementAlgorithmIdentifiers.DIRECT, ContentEncryptionAlgorithmIdentifiers.AES_128_CBC_HMAC_SHA_256, "j-DJVQ9ftUV-muUT_-yjP6dB9kuypGeT6lEGpCKOi-c");
littleJweRoundTrip(KeyManagementAlgorithmIdentifiers.DIRECT, ContentEncryptionAlgorithmIdentifiers.AES_192_CBC_HMAC_SHA_384, "X--mSrs-JGaf0ulQQFSoJGH0vjrfe_c1X--mSrs-JGaf0ulQQFSoJGH0vjrfe_c1");
littleJweRoundTrip(KeyManagementAlgorithmIdentifiers.DIRECT, ContentEncryptionAlgorithmIdentifiers.AES_256_CBC_HMAC_SHA_512, "j-DJVQ9ftUV-muUT_-yjP6dB9kuypGeT6lEGpCKOi-cj-DJVQ9ftUV-muUT_-yjP6dB9kuypGeT6lEGpCKOi-c");
JceProviderTestSupport jceProviderTestSupport = new JceProviderTestSupport();
jceProviderTestSupport.setEncryptionAlgsNeeded(AES_128_GCM, AES_192_GCM, AES_256_GCM);
jceProviderTestSupport.runWithBouncyCastleProviderIfNeeded(
new JceProviderTestSupport.RunnableTest()
{
@Override
public void runTest() throws Exception
{
littleJweRoundTrip(KeyManagementAlgorithmIdentifiers.DIRECT, AES_128_GCM, "mmp7iLc1cB7cQrEtqyb9c1");
littleJweRoundTrip(KeyManagementAlgorithmIdentifiers.DIRECT, AES_192_GCM, "X--mSrs-JGaf0ulQQFSoJGH0vjrfe_c1");
littleJweRoundTrip(KeyManagementAlgorithmIdentifiers.DIRECT, AES_256_GCM, "j-DJVQ9ftUV-muUT_-yjP6dB9kuypGeT6lEGpCKOi-c");
}
}
);
}
示例5: jwe1
import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的package包/类
@Test
public void jwe1() throws JoseException
{
String cs = "eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2Iiwia2lkIjoiOWVyIn0." +
"." +
"XAog2l7TP5-0mIPYjT2ZYg." +
"Zf6vQZhxeAfzk2AyuXsKJSo1R8aluPDvK7a6N7wvSmuIUczDhUtJFmNdXC3d4rPa." +
"XBTguLfGeGKu6YsQVnes2w";
JsonWebStructure jwx = JsonWebStructure.fromCompactSerialization(cs);
jwx.setKey(oct256bitJwk.getKey());
Assert.assertTrue(cs + " should give a JWE " + jwx, jwx instanceof JsonWebEncryption);
Assert.assertEquals(KeyManagementAlgorithmIdentifiers.DIRECT, jwx.getAlgorithmHeaderValue());
Assert.assertEquals(oct256bitJwk.getKeyId(), jwx.getKeyIdHeaderValue());
String payload = jwx.getPayload();
Assert.assertEquals(YOU_LL_GET_NOTHING_AND_LIKE_IT, payload);
}
示例6: jwe2
import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的package包/类
@Test
public void jwe2() throws JoseException
{
String cs = "eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMTI4Q0JDLUhTMjU2Iiwia2lkIjoiOWVyIn0." +
"RAqGCBMFk7O-B-glFckcFmxUr8BTTXuZk-bXAdRZxpk5Vgs_1yoUQw." +
"hyl68_ADlK4VRDYiQMQS6w." +
"xk--JKIVF4Xjxc0gRGPL30s4PSNtj685WYqXbjyItG0uSffD4ajGXdz4BO8i0sbM." +
"WXaAVpBgftXyO1HkkRvgQQ";
JsonWebStructure jwx = JsonWebStructure.fromCompactSerialization(cs);
jwx.setKey(oct256bitJwk.getKey());
Assert.assertTrue(cs + " should give a JWE " + jwx, jwx instanceof JsonWebEncryption);
Assert.assertEquals(KeyManagementAlgorithmIdentifiers.A256KW, jwx.getAlgorithmHeaderValue());
Assert.assertEquals(oct256bitJwk.getKeyId(), jwx.getKeyIdHeaderValue());
String payload = jwx.getPayload();
Assert.assertEquals(YOU_LL_GET_NOTHING_AND_LIKE_IT, payload);
}
示例7: encrypt
import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的package包/类
@Override public String encrypt(String data, PublicKey publicKey, String keyId, String contentType) throws JWEFailure {
String encrypted;
JsonWebEncryption jwe = new JsonWebEncryption();
try {
jwe.setKey(publicKey);
jwe.setPlaintext(data);
jwe.setKeyIdHeaderValue(keyId);
jwe.setContentTypeHeaderValue(contentType);
jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.RSA_OAEP_256);
jwe.setEncryptionMethodHeaderParameter(ContentEncryptionAlgorithmIdentifiers.AES_256_CBC_HMAC_SHA_512);
encrypted = jwe.getCompactSerialization();
} catch (JoseException e) {
throw new JWEFailure("An error occurred attempting to encrypt a JWE", e);
}
return encrypted;
}
示例8: encryptValue
import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的package包/类
/**
* Encrypt the value based on the seed array whose length was given during afterPropertiesSet,
* and the key and content encryption ids.
*
* @param value the value
* @return the encoded value
*/
private String encryptValue(@NotNull final String value) {
try {
final JsonWebEncryption jwe = new JsonWebEncryption();
jwe.setPayload(value);
jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.DIRECT);
jwe.setEncryptionMethodHeaderParameter(this.contentEncryptionAlgorithmIdentifier);
jwe.setKey(this.secretKeyEncryptionKey);
logger.debug("Encrypting via [{}]", this.contentEncryptionAlgorithmIdentifier);
return jwe.getCompactSerialization();
} catch (final Exception e) {
throw new RuntimeException("Ensure that you have installed JCE Unlimited Strength Jurisdiction Policy Files. "
+ e.getMessage(), e);
}
}
示例9: encryptValue
import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的package包/类
/**
* Encrypt the value based on the seed array whose length was given during init,
* and the key and content encryption ids.
*
* @param value the value
* @return the encoded value
*/
private String encryptValue(@NotNull final String value) {
try {
final JsonWebEncryption jwe = new JsonWebEncryption();
jwe.setPayload(value);
jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.DIRECT);
jwe.setEncryptionMethodHeaderParameter(this.contentEncryptionAlgorithmIdentifier);
jwe.setKey(this.secretKeyEncryptionKey);
logger.debug("Encrypting via [{}]", this.contentEncryptionAlgorithmIdentifier);
return jwe.getCompactSerialization();
} catch (final Exception e) {
throw new RuntimeException("Ensure that you have installed JCE Unlimited Strength Jurisdiction Policy Files. "
+ e.getMessage(), e);
}
}
示例10: aesEncryptDecrypt128
import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的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);
}
示例11: aesEncryptDecrypt256
import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的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);
}
示例12: jweEncrypt
import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的package包/类
private static String jweEncrypt(Key key, String payload, boolean isPayloadJWT) throws Exception {
JsonWebEncryption jwe = new JsonWebEncryption();
jwe.setAlgorithmHeaderValue(
KeyManagementAlgorithmIdentifiers.RSA_OAEP);
jwe.setEncryptionMethodHeaderParameter(
ContentEncryptionAlgorithmIdentifiers.AES_256_CBC_HMAC_SHA_512);
jwe.setKey(key);
if (isPayloadJWT) jwe.setContentTypeHeaderValue("JWT");
jwe.setPayload(payload);
return jwe.getCompactSerialization();
}
示例13: jweDecrypt
import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的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();
}
示例14: jwtProcess
import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的package包/类
private static String jwtProcess(Key jweKey, Key jwsKey, String jwt) throws Exception {
AlgorithmConstraints jwsAlgConstraints =
new AlgorithmConstraints(
ConstraintType.WHITELIST,
AlgorithmIdentifiers.HMAC_SHA512);
AlgorithmConstraints jweAlgConstraints =
new AlgorithmConstraints(
ConstraintType.WHITELIST,
KeyManagementAlgorithmIdentifiers.RSA_OAEP);
AlgorithmConstraints jweEncConstraints =
new AlgorithmConstraints(
ConstraintType.WHITELIST,
ContentEncryptionAlgorithmIdentifiers.AES_256_CBC_HMAC_SHA_512);
JwtConsumer jwtConsumer =
new JwtConsumerBuilder()
.setRequireExpirationTime()
.setMaxFutureValidityInMinutes(300)
.setRequireSubject()
.setExpectedIssuer("issue-idp-1")
.setExpectedAudience("aud-1", "aud-2")
.setDecryptionKey(jweKey)
.setVerificationKey(jwsKey)
.setRelaxVerificationKeyValidation()
.setJwsAlgorithmConstraints(jwsAlgConstraints)
.setJweAlgorithmConstraints(jweAlgConstraints)
.setJweContentEncryptionAlgorithmConstraints(jweEncConstraints)
.build();
try {
return jwtConsumer.processToClaims(jwt).toJson();
} catch (InvalidJwtException e) {
System.out.println("Invalid JWT! " + e);
return null;
}
}
示例15: testParseExampleSymmetricKeys
import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的package包/类
public void testParseExampleSymmetricKeys() throws JoseException
{
// from https://tools.ietf.org/html/draft-ietf-jose-json-web-key Appendix A.3
String jwkJson = "{\"keys\":\n" +
" [\n" +
" {\"kty\":\"oct\",\n" +
" \"alg\":\"A128KW\",\n" +
" \"k\":\"GawgguFyGrWKav7AX4VKUg\"},\n" +
"\n" +
" {\"kty\":\"oct\",\n" +
" \"k\":\"AyM1SysPpbyDfgZld3umj1qzKObwVMkoqQ-EstJQLr_T-1qS0gZH75\n" +
" aKtMN3Yj0iPS4hcgUuTwjAzZr1Z9CAow\",\n" +
" \"kid\":\"HMAC key used in JWS A.1 example\"}\n" +
" ]\n" +
" }\n";
JsonWebKeySet jwkSet = new JsonWebKeySet(jwkJson);
Collection<JsonWebKey> jwks = jwkSet.getJsonWebKeys();
assertEquals(2, jwks.size());
Iterator<JsonWebKey> iterator = jwks.iterator();
assertTrue(iterator.next() instanceof OctetSequenceJsonWebKey);
assertTrue(iterator.next() instanceof OctetSequenceJsonWebKey);
assertFalse(iterator.hasNext());
JsonWebKey jwk2 = jwkSet.findJsonWebKey("HMAC key used in JWS A.1 example", null, null, null);
Key key2 = jwk2.getKey();
assertNotNull(key2);
assertEquals(64, key2.getEncoded().length);
JsonWebKey jwk1 = jwkSet.findJsonWebKey(null, null, null, KeyManagementAlgorithmIdentifiers.A128KW);
Key key1 = jwk1.getKey();
assertNotNull(key1);
assertEquals(16, key1.getEncoded().length);
}