本文整理了Java中com.nimbusds.jose.jwk.JWK.parse()
方法的一些代码示例,展示了JWK.parse()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JWK.parse()
方法的具体详情如下:
包路径:com.nimbusds.jose.jwk.JWK
类名称:JWK
方法名:parse
[英]Parses a JWK from the specified JSON object string representation. The JWK must be an ECKey, an RSAKey, or a OctetSequenceKey.
[中]从指定的JSON对象字符串表示形式解析JWK。JWK必须是ECKey、RSAKey或OctetSequenceKey。
代码示例来源:origin: de.adorsys.sts/sts-simple-encryption
private JWK tryToParseJwk(String key) {
JWK parsedKey;
try {
parsedKey = JWK.parse(key);
} catch (ParseException e) {
throw new IllegalArgumentException(e);
}
return parsedKey;
}
}
代码示例来源:origin: de.adorsys.sts/sts-simple-encryption
private static Key extractSecretKey(String jwkAsString) {
Key key;
try {
JWK parsedKey = JWK.parse(jwkAsString);
key = KeyConverter.toPrivateOrSecret(parsedKey, "AES");
} catch (ParseException e) {
throw new IllegalArgumentException(e);
}
return key;
}
}
代码示例来源:origin: com.nimbusds/nimbus-jose-jwt
/**
* Parses a JWK from the specified JSON object string representation.
* The JWK must be an {@link ECKey}, an {@link RSAKey}, or a
* {@link OctetSequenceKey}.
*
* @param s The JSON object string to parse. Must not be {@code null}.
*
* @return The JWK.
*
* @throws ParseException If the string couldn't be parsed to a
* supported JWK.
*/
public static JWK parse(final String s)
throws ParseException {
return parse(JSONObjectUtils.parse(s));
}
代码示例来源:origin: com.nimbusds/nimbus-jose-jwt
keys.add(JWK.parse(keyJSON));
代码示例来源:origin: com.nimbusds/nimbus-jose-jwt
return parse(cert);
代码示例来源:origin: GluuFederation/oxAuth
@Override
public String sign(String signingInput, String keyId, String sharedSecret, SignatureAlgorithm signatureAlgorithm) throws Exception {
RSAPrivateKey privateKey = ((RSAKey) JWK.parse(senderJwkJson)).toRSAPrivateKey();
Signature signature = Signature.getInstance(signatureAlgorithm.getAlgorithm(), "BC");
signature.initSign(privateKey);
signature.update(signingInput.getBytes());
return Base64Util.base64urlencode(signature.sign());
}
代码示例来源:origin: GluuFederation/oxAuth
public boolean testDecryptWithGluuDecrypter(String jwe) {
try {
JWK jwk = JWK.parse(recipientJwkJson);
RSAPrivateKey rsaPrivateKey = ((RSAKey) jwk).toRSAPrivateKey();
JweDecrypterImpl decrypter = new JweDecrypterImpl(rsaPrivateKey);
decrypter.setKeyEncryptionAlgorithm(KeyEncryptionAlgorithm.RSA_OAEP);
decrypter.setBlockEncryptionAlgorithm(BlockEncryptionAlgorithm.A128GCM);
final String decryptedPayload = decrypter.decrypt(jwe).getClaims().toJsonString().toString();
System.out.println("Gluu decrypt succeed: " + decryptedPayload);
if (decryptedPayload.equals(PAYLOAD)) {
return true;
}
} catch (Exception e) {
System.out.println("Gluu decrypt failed: " + e.getMessage());
e.printStackTrace();
}
return false;
}
代码示例来源:origin: com.nimbusds/nimbus-jose-jwt
header = header.jwkURL(JSONObjectUtils.getURI(jsonObject, name));
} else if("jwk".equals(name)) {
header = header.jwk(JWK.parse(JSONObjectUtils.getJSONObject(jsonObject, name)));
} else if("x5u".equals(name)) {
header = header.x509CertURL(JSONObjectUtils.getURI(jsonObject, name));
代码示例来源:origin: com.nimbusds/nimbus-jose-jwt
header = header.jwkURL(JSONObjectUtils.getURI(jsonObject, name));
} else if("jwk".equals(name)) {
header = header.jwk(JWK.parse(JSONObjectUtils.getJSONObject(jsonObject, name)));
} else if("x5u".equals(name)) {
header = header.x509CertURL(JSONObjectUtils.getURI(jsonObject, name));
header = header.keyID(JSONObjectUtils.getString(jsonObject, name));
} else if("epk".equals(name)) {
header = header.ephemeralPublicKey(JWK.parse(JSONObjectUtils.getJSONObject(jsonObject, name)));
} else if("zip".equals(name)) {
header = header.compressionAlgorithm(new CompressionAlgorithm(JSONObjectUtils.getString(jsonObject, name)));
代码示例来源:origin: GluuFederation/oxAuth
private boolean testDecryptNimbusJoseJwt(String jwe) {
try {
EncryptedJWT encryptedJwt = EncryptedJWT.parse(jwe);
//EncryptedJWT encryptedJwt = EncryptedJWT.parse(encryptWithGluu());
//EncryptedJWT encryptedJwt = EncryptedJWT.parse(encryptWithNimbus());
JWK jwk = JWK.parse(recipientJwkJson);
RSAPrivateKey rsaPrivateKey = ((RSAKey) jwk).toRSAPrivateKey();
JWEDecrypter decrypter = new RSADecrypter(rsaPrivateKey);
decrypter.getJCAContext().setProvider(BouncyCastleProviderSingleton.getInstance());
encryptedJwt.decrypt(decrypter);
final String decryptedPayload = new String(Base64Util.base64urldecode(encryptedJwt.getPayload().toString()));
System.out.println("Nimbusds decrypt succeed: " + decryptedPayload);
if (decryptedPayload.equals(PAYLOAD)) {
return true;
}
} catch (Exception e) {
System.out.println("Nimbusds decrypt failed: " + e.getMessage());
e.printStackTrace();
}
return false;
}
代码示例来源:origin: GluuFederation/oxAuth
private String encryptWithNimbusJoseJwt() {
RSAKey senderJWK = (RSAKey) JWK.parse(senderJwkJson);
RSAKey recipientPublicJWK = (RSAKey) (JWK.parse(recipientJwkJson));
代码示例来源:origin: GluuFederation/oxAuth
private void decryptAndValidateSignatureWithGluu(String jweString) throws ParseException, JOSEException, InvalidJweException, JSONException, InvalidJwtException {
JWK jwk = JWK.parse(recipientJwkJson);
RSAPrivateKey rsaPrivateKey = ((RSAKey) jwk).toRSAPrivateKey();
JweDecrypterImpl decrypter = new JweDecrypterImpl(rsaPrivateKey);
decrypter.setKeyEncryptionAlgorithm(KeyEncryptionAlgorithm.RSA_OAEP);
decrypter.setBlockEncryptionAlgorithm(BlockEncryptionAlgorithm.A128GCM);
final Jwe jwe = decrypter.decrypt(jweString);
assertEquals(JwtType.JWT, jwe.getHeader().getContentType());
final Jwt jwt = jwe.getSignedJWTPayload();
final RSAPublicKey senderPublicKey = RSAKeyFactory.valueOf(getSenderWebKey()).getPublicKey();
Assert.assertTrue(new RSASigner(SignatureAlgorithm.RS256, senderPublicKey).validate(jwt));
System.out.println("Gluu decrypt and nested jwt signature verification succeed: " + jwt.getClaims().toJsonString());
}
}
代码示例来源:origin: GluuFederation/oxAuth
private String encryptWithGluuJweEncrypter() {
try {
RSAKey recipientPublicJWK = (RSAKey) (JWK.parse(recipientJwkJson));
BlockEncryptionAlgorithm blockEncryptionAlgorithm = BlockEncryptionAlgorithm.A128GCM;
KeyEncryptionAlgorithm keyEncryptionAlgorithm = KeyEncryptionAlgorithm.RSA_OAEP;
Jwe jwe = new Jwe();
jwe.getHeader().setType(JwtType.JWT);
jwe.getHeader().setAlgorithm(keyEncryptionAlgorithm);
jwe.getHeader().setEncryptionMethod(blockEncryptionAlgorithm);
jwe.getClaims().setIssuer("https:devgluu.saminet.local");
jwe.getClaims().setSubjectIdentifier("testing");
jwe.getHeader().setKeyId("1");
JweEncrypterImpl encrypter = new JweEncrypterImpl(keyEncryptionAlgorithm, blockEncryptionAlgorithm, recipientPublicJWK.toPublicKey());
jwe = encrypter.encrypt(jwe);
// System.out.println("EncodedHeader: " + jwe.getEncodedHeader());
// System.out.println("EncodedEncryptedKey: " + jwe.getEncodedEncryptedKey());
// System.out.println("EncodedInitializationVector: " + jwe.getEncodedInitializationVector());
// System.out.println("EncodedCiphertext: " + jwe.getEncodedCiphertext());
// System.out.println("EncodedIntegrityValue: " + jwe.getEncodedIntegrityValue());
return jwe.toString();
} catch (Exception e) {
System.out.println("Error encryption with Gluu JweEncrypter: " + e.getMessage());
return null;
}
}
代码示例来源:origin: GluuFederation/oxAuth
@Test
public void nestedJWT() throws Exception {
RSAKey senderJWK = (RSAKey) JWK.parse(senderJwkJson);
RSAKey recipientPublicJWK = (RSAKey) (JWK.parse(recipientJwkJson));
// Create JWT
SignedJWT signedJWT = new SignedJWT(
new JWSHeader.Builder(JWSAlgorithm.RS256).keyID(senderJWK.getKeyID()).build(),
new JWTClaimsSet.Builder()
.subject("testi")
.issuer("https:devgluu.saminet.local")
.build());
signedJWT.sign(new RSASSASigner(senderJWK));
JWEObject jweObject = new JWEObject(
new JWEHeader.Builder(JWEAlgorithm.RSA_OAEP, EncryptionMethod.A128GCM)
.contentType("JWT") // required to indicate nested JWT
.build(),
new Payload(signedJWT));
// Encrypt with the recipient's public key
RSAEncrypter encrypter = new RSAEncrypter(recipientPublicJWK);
jweObject.encrypt(encrypter);
final String jweString = jweObject.serialize();
decryptAndValidateSignatureWithGluu(jweString);
}
代码示例来源:origin: GluuFederation/oxAuth
jwt = jwtSigner.sign();
RSAKey recipientPublicJWK = (RSAKey) (JWK.parse(recipientJwkJson));
内容来源于网络,如有侵权,请联系作者删除!