本文整理汇总了Java中com.nimbusds.jose.EncryptionMethod类的典型用法代码示例。如果您正苦于以下问题:Java EncryptionMethod类的具体用法?Java EncryptionMethod怎么用?Java EncryptionMethod使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EncryptionMethod类属于com.nimbusds.jose包,在下文中一共展示了EncryptionMethod类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: encode
import com.nimbusds.jose.EncryptionMethod; //导入依赖的package包/类
public String encode(String payload) {
JWEAlgorithm alg = JWEAlgorithm.A128KW;
EncryptionMethod encryptionMethod = EncryptionMethod.A128GCM;
try {
byte[] decodedKey = Base64.getDecoder().decode(encodedKeypair);
SecretKey key = new SecretKeySpec(decodedKey, 0, decodedKey.length, "AES");
JWEObject jwe = new JWEObject(
new JWEHeader(alg, encryptionMethod),
new Payload(payload));
jwe.encrypt(new AESEncrypter(key));
return jwe.serialize();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
开发者ID:PacktPublishing,项目名称:OAuth-2.0-Cookbook,代码行数:18,代码来源:JweTokenSerializer.java
示例2: encrypt
import com.nimbusds.jose.EncryptionMethod; //导入依赖的package包/类
public String encrypt(String data, String keyId, String aesKey) {
try {
byte[] keyBytes = Base64.decode(aesKey);
SecretKeySpec secretKey = new SecretKeySpec(keyBytes, 0, keyBytes.length, "AES");
JWEAlgorithm jweAlgorithm = JWEAlgorithm.A256KW;
EncryptionMethod encryptionMethod = EncryptionMethod.A128GCM;
JWEHeader.Builder headerBuilder = new JWEHeader.Builder(jweAlgorithm, encryptionMethod);
headerBuilder.keyID(keyId);
JWEHeader header = headerBuilder.build();
JWEEncrypter encrypter = new AESEncrypter(secretKey);
encrypter.getJCAContext().setProvider(BouncyCastleProviderSingleton.getInstance());
JWEObject jweObject = new JWEObject(header, new Payload(data));
jweObject.encrypt(encrypter);
return jweObject.serialize();
} catch (Exception e) {
throw new CryptoException("Exception encrypting data: " + e.getMessage(), e);
}
}
开发者ID:americanexpress,项目名称:amex-api-java-client-core,代码行数:23,代码来源:EncryptionUtility.java
示例3: getToken
import com.nimbusds.jose.EncryptionMethod; //导入依赖的package包/类
public Result getToken() throws NoSuchAlgorithmException, NoSuchProviderException {
CommonProfile prof = new CommonProfile();
prof.setClientName("flo");
prof.setId(UUID.randomUUID().toString());
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
keyGen.initialize(1024, random);
KeyPair pair = keyGen.generateKeyPair();
EncryptionConfiguration ee = new RSAEncryptionConfiguration(pair, JWEAlgorithm.RSA1_5,
EncryptionMethod.A256CBC_HS512);
final List<CommonProfile> profiles = ImmutableList.of(prof);
final JwtGenerator<CommonProfile> generator = new JwtGenerator<>();
generator.setEncryptionConfiguration(ee);
String token = "";
if (CommonHelper.isNotEmpty(profiles)) {
token = generator.generate(profiles.get(0));
}
return ok(Json.toJson(token));
}
开发者ID:daflockinger,项目名称:spongeblog,代码行数:24,代码来源:AuthenticateController.java
示例4: testEncryptDecryptPlainJWT
import com.nimbusds.jose.EncryptionMethod; //导入依赖的package包/类
@Test
public void testEncryptDecryptPlainJWT() throws ParseException, JOSEException {
final SecretEncryptionConfiguration config = new SecretEncryptionConfiguration(MAC_SECRET);
config.setAlgorithm(JWEAlgorithm.A256GCMKW);
config.setMethod(EncryptionMethod.A128GCM);
final JWT jwt = new PlainJWT(buildClaims());
final String token = config.encrypt(jwt);
final EncryptedJWT encryptedJwt = (EncryptedJWT) JWTParser.parse(token);
config.decrypt(encryptedJwt);
final JWT jwt2 = encryptedJwt;
assertEquals(VALUE, jwt2.getJWTClaimsSet().getSubject());
}
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:14,代码来源:SecretEncryptionConfigurationTests.java
示例5: testEncryptDecryptSignedJWT
import com.nimbusds.jose.EncryptionMethod; //导入依赖的package包/类
@Test
public void testEncryptDecryptSignedJWT() throws ParseException, JOSEException {
final SecretSignatureConfiguration macConfig = new SecretSignatureConfiguration(MAC_SECRET);
final SignedJWT signedJWT = macConfig.sign(buildClaims());
final ECEncryptionConfiguration config = new ECEncryptionConfiguration(buildKeyPair());
config.setAlgorithm(JWEAlgorithm.ECDH_ES_A128KW);
config.setMethod(EncryptionMethod.A192CBC_HS384);
final String token = config.encrypt(signedJWT);
final EncryptedJWT encryptedJwt = (EncryptedJWT) JWTParser.parse(token);
config.decrypt(encryptedJwt);
final SignedJWT signedJWT2 = encryptedJwt.getPayload().toSignedJWT();
assertEquals(VALUE, signedJWT2.getJWTClaimsSet().getSubject());
}
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:15,代码来源:ECEncryptionConfigurationTests.java
示例6: testEncryptDecryptPlainJWT
import com.nimbusds.jose.EncryptionMethod; //导入依赖的package包/类
@Test
public void testEncryptDecryptPlainJWT() throws ParseException, JOSEException {
final ECEncryptionConfiguration config = new ECEncryptionConfiguration(buildKeyPair());
config.setAlgorithm(JWEAlgorithm.ECDH_ES_A256KW);
config.setMethod(EncryptionMethod.A128GCM);
final JWT jwt = new PlainJWT(buildClaims());
final String token = config.encrypt(jwt);
final EncryptedJWT encryptedJwt = (EncryptedJWT) JWTParser.parse(token);
config.decrypt(encryptedJwt);
final JWT jwt2 = encryptedJwt;
assertEquals(VALUE, jwt2.getJWTClaimsSet().getSubject());
}
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:14,代码来源:ECEncryptionConfigurationTests.java
示例7: testEncryptMissingKey
import com.nimbusds.jose.EncryptionMethod; //导入依赖的package包/类
@Test
public void testEncryptMissingKey() throws ParseException, JOSEException {
final ECEncryptionConfiguration config = new ECEncryptionConfiguration();
config.setAlgorithm(JWEAlgorithm.ECDH_ES_A256KW);
config.setMethod(EncryptionMethod.A128GCM);
final JWT jwt = new PlainJWT(buildClaims());
TestsHelper.expectException(() -> config.encrypt(jwt), TechnicalException.class, "publicKey cannot be null");
}
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:10,代码来源:ECEncryptionConfigurationTests.java
示例8: testDecryptMissingKey
import com.nimbusds.jose.EncryptionMethod; //导入依赖的package包/类
@Test
public void testDecryptMissingKey() throws ParseException, JOSEException {
final ECEncryptionConfiguration config = new ECEncryptionConfiguration(buildKeyPair());
config.setAlgorithm(JWEAlgorithm.ECDH_ES_A192KW);
config.setMethod(EncryptionMethod.A128GCM);
final JWT jwt = new PlainJWT(buildClaims());
final String token = config.encrypt(jwt);
final EncryptedJWT encryptedJwt = (EncryptedJWT) JWTParser.parse(token);
final ECEncryptionConfiguration config2 = new ECEncryptionConfiguration();
config2.setAlgorithm(JWEAlgorithm.ECDH_ES_A192KW);
config2.setMethod(EncryptionMethod.A128GCM);
TestsHelper.expectException(() -> config2.decrypt(encryptedJwt), TechnicalException.class, "privateKey cannot be null");
}
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:15,代码来源:ECEncryptionConfigurationTests.java
示例9: testEncryptDecryptSignedJWT
import com.nimbusds.jose.EncryptionMethod; //导入依赖的package包/类
@Test
public void testEncryptDecryptSignedJWT() throws ParseException, JOSEException {
final SecretSignatureConfiguration macConfig = new SecretSignatureConfiguration(MAC_SECRET);
final SignedJWT signedJWT = macConfig.sign(buildClaims());
final RSAEncryptionConfiguration config = new RSAEncryptionConfiguration(buildKeyPair());
config.setAlgorithm(JWEAlgorithm.RSA1_5);
config.setMethod(EncryptionMethod.A192CBC_HS384);
final String token = config.encrypt(signedJWT);
final EncryptedJWT encryptedJwt = (EncryptedJWT) JWTParser.parse(token);
config.decrypt(encryptedJwt);
final SignedJWT signedJWT2 = encryptedJwt.getPayload().toSignedJWT();
assertEquals(VALUE, signedJWT2.getJWTClaimsSet().getSubject());
}
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:15,代码来源:RSAEncryptionConfigurationTests.java
示例10: testEncryptDecryptPlainJWT
import com.nimbusds.jose.EncryptionMethod; //导入依赖的package包/类
@Test
public void testEncryptDecryptPlainJWT() throws ParseException, JOSEException {
final RSAEncryptionConfiguration config = new RSAEncryptionConfiguration(buildKeyPair());
config.setAlgorithm(JWEAlgorithm.RSA_OAEP);
config.setMethod(EncryptionMethod.A128GCM);
final JWT jwt = new PlainJWT(buildClaims());
final String token = config.encrypt(jwt);
final EncryptedJWT encryptedJwt = (EncryptedJWT) JWTParser.parse(token);
config.decrypt(encryptedJwt);
final JWT jwt2 = encryptedJwt;
assertEquals(VALUE, jwt2.getJWTClaimsSet().getSubject());
}
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:14,代码来源:RSAEncryptionConfigurationTests.java
示例11: testEncryptMissingKey
import com.nimbusds.jose.EncryptionMethod; //导入依赖的package包/类
@Test
public void testEncryptMissingKey() throws ParseException, JOSEException {
final RSAEncryptionConfiguration config = new RSAEncryptionConfiguration();
config.setAlgorithm(JWEAlgorithm.RSA_OAEP);
config.setMethod(EncryptionMethod.A128GCM);
final JWT jwt = new PlainJWT(buildClaims());
TestsHelper.expectException(() -> config.encrypt(jwt), TechnicalException.class, "publicKey cannot be null");
}
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:10,代码来源:RSAEncryptionConfigurationTests.java
示例12: testDecryptMissingKey
import com.nimbusds.jose.EncryptionMethod; //导入依赖的package包/类
@Test
public void testDecryptMissingKey() throws ParseException, JOSEException {
final RSAEncryptionConfiguration config = new RSAEncryptionConfiguration(buildKeyPair());
config.setAlgorithm(JWEAlgorithm.RSA_OAEP);
config.setMethod(EncryptionMethod.A128GCM);
final JWT jwt = new PlainJWT(buildClaims());
final String token = config.encrypt(jwt);
final EncryptedJWT encryptedJwt = (EncryptedJWT) JWTParser.parse(token);
final RSAEncryptionConfiguration config2 = new RSAEncryptionConfiguration();
config2.setAlgorithm(JWEAlgorithm.RSA_OAEP);
config2.setMethod(EncryptionMethod.A128GCM);
TestsHelper.expectException(() -> config2.decrypt(encryptedJwt), TechnicalException.class, "privateKey cannot be null");
}
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:15,代码来源:RSAEncryptionConfigurationTests.java
示例13: testJwtGenerationA256CBC
import com.nimbusds.jose.EncryptionMethod; //导入依赖的package包/类
@Test
public void testJwtGenerationA256CBC() {
final JwtGenerator<CommonProfile> g = new JwtGenerator<>(new SecretSignatureConfiguration(MAC_SECRET + MAC_SECRET + MAC_SECRET + MAC_SECRET + MAC_SECRET + MAC_SECRET + MAC_SECRET + MAC_SECRET),
new SecretEncryptionConfiguration(KEY2 + KEY2)
);
((SecretEncryptionConfiguration) g.getEncryptionConfiguration()).setMethod(EncryptionMethod.A256CBC_HS512);
final String g1 = g.generate(new CommonProfile());
assertNotNull(g1);
}
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:10,代码来源:JwtTests.java
示例14: testJwtGenerationA256GCM
import com.nimbusds.jose.EncryptionMethod; //导入依赖的package包/类
@Test
public void testJwtGenerationA256GCM() {
final JwtGenerator<CommonProfile> g = new JwtGenerator<>(
new SecretSignatureConfiguration(MAC_SECRET + MAC_SECRET + MAC_SECRET + MAC_SECRET + MAC_SECRET + MAC_SECRET + MAC_SECRET + MAC_SECRET),
new SecretEncryptionConfiguration(MAC_SECRET)
);
((SecretEncryptionConfiguration) g.getEncryptionConfiguration()).setMethod(EncryptionMethod.A256GCM);
final String g1 = g.generate(new CommonProfile());
assertNotNull(g1);
}
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:11,代码来源:JwtTests.java
示例15: login
import com.nimbusds.jose.EncryptionMethod; //导入依赖的package包/类
@POST
@Path("/login")
@Produces(MediaType.TEXT_PLAIN)
public String login(@FormParam("userName") String userName, @FormParam("password") String password) {
JwtGenerator<JwtProfile> gen = new JwtGenerator<>(jwtKey);
gen.setEncryptionMethod(EncryptionMethod.A128CBC_HS256);
JwtProfile profile = new JwtProfile();
profile.addAttribute("userName", userName);
return gen.generate(profile);
}
开发者ID:mocircle,项目名称:devsuite-backend,代码行数:13,代码来源:DemoResource.java
示例16: getAuthenticator
import com.nimbusds.jose.EncryptionMethod; //导入依赖的package包/类
@Override
protected Authenticator<TokenCredentials> getAuthenticator(final Credential credential) {
final TokenCredential tokenCredential = (TokenCredential) credential;
LOGGER.debug("Locating token secret for service [{}]", tokenCredential.getService());
final RegisteredService service = this.servicesManager.findServiceBy(tokenCredential.getService());
final String signingSecret = getRegisteredServiceJwtSigningSecret(service);
final String encryptionSecret = getRegisteredServiceJwtEncryptionSecret(service);
final String signingSecretAlg =
StringUtils.defaultString(getRegisteredServiceJwtSecret(service, TokenConstants.PROPERTY_NAME_TOKEN_SECRET_SIGNING_ALG),
JWSAlgorithm.HS256.getName());
final String encryptionSecretAlg =
StringUtils.defaultString(getRegisteredServiceJwtSecret(service, TokenConstants.PROPERTY_NAME_TOKEN_SECRET_ENCRYPTION_ALG),
JWEAlgorithm.DIR.getName());
final String encryptionSecretMethod =
StringUtils.defaultString(getRegisteredServiceJwtSecret(service, TokenConstants.PROPERTY_NAME_TOKEN_SECRET_ENCRYPTION_METHOD),
EncryptionMethod.A192CBC_HS384.getName());
if (StringUtils.isNotBlank(signingSecret)) {
Set<Algorithm> sets = new HashSet<>();
sets.addAll(JWSAlgorithm.Family.EC);
sets.addAll(JWSAlgorithm.Family.HMAC_SHA);
sets.addAll(JWSAlgorithm.Family.RSA);
sets.addAll(JWSAlgorithm.Family.SIGNATURE);
final JWSAlgorithm signingAlg = findAlgorithmFamily(sets, signingSecretAlg);
final JwtAuthenticator a = new JwtAuthenticator();
a.setSignatureConfiguration(new SecretSignatureConfiguration(signingSecret, signingAlg));
if (StringUtils.isNotBlank(encryptionSecret)) {
sets = new HashSet<>();
sets.addAll(JWEAlgorithm.Family.AES_GCM_KW);
sets.addAll(JWEAlgorithm.Family.AES_KW);
sets.addAll(JWEAlgorithm.Family.ASYMMETRIC);
sets.addAll(JWEAlgorithm.Family.ECDH_ES);
sets.addAll(JWEAlgorithm.Family.PBES2);
sets.addAll(JWEAlgorithm.Family.RSA);
sets.addAll(JWEAlgorithm.Family.SYMMETRIC);
final JWEAlgorithm encAlg = findAlgorithmFamily(sets, encryptionSecretAlg);
sets = new HashSet<>();
sets.addAll(EncryptionMethod.Family.AES_CBC_HMAC_SHA);
sets.addAll(EncryptionMethod.Family.AES_GCM);
final EncryptionMethod encMethod = findAlgorithmFamily(sets, encryptionSecretMethod);
a.setEncryptionConfiguration(new SecretEncryptionConfiguration(encryptionSecret, encAlg, encMethod));
} else {
LOGGER.warn("JWT authentication is configured to share a single key for both signing/encryption");
}
return a;
}
LOGGER.warn("No token signing secret is defined for service [{}]. Ensure [{}] property is defined for service",
service.getServiceId(), TokenConstants.PROPERTY_NAME_TOKEN_SECRET_SIGNING);
return null;
}
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:61,代码来源:TokenAuthenticationHandler.java
示例17: testMissingAlgorithm
import com.nimbusds.jose.EncryptionMethod; //导入依赖的package包/类
@Test
public void testMissingAlgorithm() {
final SecretEncryptionConfiguration config = new SecretEncryptionConfiguration(SECRET, null, EncryptionMethod.A128CBC_HS256);
TestsHelper.expectException(config::init, TechnicalException.class, "algorithm cannot be null");
}
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:6,代码来源:SecretEncryptionConfigurationTests.java
示例18: testUnsupportedAlgorithm
import com.nimbusds.jose.EncryptionMethod; //导入依赖的package包/类
@Test
public void testUnsupportedAlgorithm() {
final SecretEncryptionConfiguration config = new SecretEncryptionConfiguration(SECRET, JWEAlgorithm.ECDH_ES, EncryptionMethod.A128CBC_HS256);
TestsHelper.expectException(config::init, TechnicalException.class, "Only the direct and AES algorithms are supported with the appropriate encryption method");
}
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:6,代码来源:SecretEncryptionConfigurationTests.java
示例19: testMissingAlgorithm
import com.nimbusds.jose.EncryptionMethod; //导入依赖的package包/类
@Test
public void testMissingAlgorithm() {
final ECEncryptionConfiguration config = new ECEncryptionConfiguration(buildKeyPair(), null, EncryptionMethod.A128CBC_HS256);
TestsHelper.expectException(config::init, TechnicalException.class, "algorithm cannot be null");
}
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:6,代码来源:ECEncryptionConfigurationTests.java
示例20: testUnsupportedAlgorithm
import com.nimbusds.jose.EncryptionMethod; //导入依赖的package包/类
@Test
public void testUnsupportedAlgorithm() {
final ECEncryptionConfiguration config = new ECEncryptionConfiguration(buildKeyPair(), JWEAlgorithm.RSA_OAEP_256, EncryptionMethod.A128CBC_HS256);
TestsHelper.expectException(config::init, TechnicalException.class, "Only Elliptic-curve algorithms are supported with the appropriate encryption method");
}
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:6,代码来源:ECEncryptionConfigurationTests.java
注:本文中的com.nimbusds.jose.EncryptionMethod类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论