當前位置: 首頁>>代碼示例>>Java>>正文


Java JWSAlgorithm.RS256屬性代碼示例

本文整理匯總了Java中com.nimbusds.jose.JWSAlgorithm.RS256屬性的典型用法代碼示例。如果您正苦於以下問題:Java JWSAlgorithm.RS256屬性的具體用法?Java JWSAlgorithm.RS256怎麽用?Java JWSAlgorithm.RS256使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在com.nimbusds.jose.JWSAlgorithm的用法示例。


在下文中一共展示了JWSAlgorithm.RS256屬性的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getSignedContent

public String getSignedContent(String content) {
    Payload contentPayload = new Payload(content);

    try {
        RSASSASigner rsa = new RSASSASigner((RSAPrivateKey) clientJwk);
        JWSAlgorithm alg = JWSAlgorithm.RS256;
        JWSHeader header = new JWSHeader.Builder(alg)
            .keyID(clientJwk.getKeyID())
            .build();
        JWSObject jws = new JWSObject(header, contentPayload);
        jws.sign(rsa);
        return jws.serialize();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:PacktPublishing,項目名稱:OAuth-2.0-Cookbook,代碼行數:16,代碼來源:JwkKeyPairManager.java

示例2: defineJWSAlgorithm

public JWSAlgorithm defineJWSAlgorithm(JWTParametersSigning parametersSigning) {
    checkDependencies();

    JWSAlgorithm result;

    switch (parametersSigning.getSecretKeyType()) {
        case HMAC:
            result = hmacAlgorithmFactory.determineOptimalAlgorithm(((HMACSecret) parametersSigning.getJWK()).toSecretKey().getEncoded());
            break;
        case RSA:
            result = JWSAlgorithm.RS256; // FIXME Is this always (what about 384 and 512
            break;
        case EC:
            result = JWSAlgorithm.ES256; // FIXME Is this always (what about 384 and 512
            break;
        default:
            throw new IllegalArgumentException(String.format("Unsupported value for SecretKeyType : %s", parametersSigning.getSecretKeyType()));
    }

    return result;

}
 
開發者ID:atbashEE,項目名稱:atbash-octopus,代碼行數:22,代碼來源:JWTSignerFactory.java

示例3: getAadJwtTokenValidator

private ConfigurableJWTProcessor<SecurityContext> getAadJwtTokenValidator()
        throws MalformedURLException {
    final ConfigurableJWTProcessor<SecurityContext> jwtProcessor = new DefaultJWTProcessor<>();
    final JWKSource<SecurityContext> keySource = new RemoteJWKSet<>(
            new URL(KEY_DISCOVERY_URI));
    final JWSAlgorithm expectedJWSAlg = JWSAlgorithm.RS256;
    final JWSKeySelector<SecurityContext> keySelector = new JWSVerificationKeySelector<>(expectedJWSAlg, keySource);
    jwtProcessor.setJWSKeySelector(keySelector);

    jwtProcessor.setJWTClaimsSetVerifier(new DefaultJWTClaimsVerifier<SecurityContext>() {
        @Override
        public void verify(JWTClaimsSet claimsSet, SecurityContext ctx) throws BadJWTException {
            super.verify(claimsSet, ctx);
            final String issuer = claimsSet.getIssuer();
            if (issuer == null || !issuer.contains("https://sts.windows.net/")) {
                throw new BadJWTException("Invalid token issuer");
            }
        }
    });
    return jwtProcessor;
}
 
開發者ID:Microsoft,項目名稱:azure-spring-boot,代碼行數:21,代碼來源:UserPrincipal.java

示例4: generateCookieBody

String generateCookieBody(int secondsToLive) {
    RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
    JWSSigner signer = new RSASSASigner(privateKey);

    DateTime expDate = new DateTime((new Date()).getTime() + secondsToLive * 1000);

    JWTClaimsSet claimsSet = new JWTClaimsSet.Builder()
            .issuer("digital-display-garden")
            .claim("exp", expDate.toString())
            .build();

    SignedJWT signedJWT = new SignedJWT(
            new JWSHeader(JWSAlgorithm.RS256),
            claimsSet
    );
    try {
        signedJWT.sign(signer);
        return signedJWT.serialize();
    } catch (JOSEException e) {
        e.printStackTrace();
        return "";
    }
}
 
開發者ID:UMM-CSci-3601-S17,項目名稱:digital-display-garden-iteration-4-dorfner-v2,代碼行數:23,代碼來源:Auth.java

示例5: generateSharedGoogleSecret

String generateSharedGoogleSecret(String originatingURL) {
    RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
    JWSSigner signer = new RSASSASigner(privateKey);

    // Expire in 60 seconds
    DateTime expDate = new DateTime((new Date()).getTime() + 60 * 1000);

    JWTClaimsSet claimsSet = new JWTClaimsSet.Builder()
            .issuer("digital-display-garden")
            .claim("originatingURL", originatingURL)
            .claim("exp", expDate.toString())
            .build();

    SignedJWT signedJWT = new SignedJWT(
            new JWSHeader(JWSAlgorithm.RS256),
            claimsSet
    );
    try {
        signedJWT.sign(signer);
        return signedJWT.serialize();
    } catch (JOSEException e) {
        e.printStackTrace();
        return "";
    }
}
 
開發者ID:UMM-CSci-3601-S17,項目名稱:digital-display-garden-iteration-4-dorfner-v2,代碼行數:25,代碼來源:Auth.java

示例6: sign

public String sign(String algorithm, String kid, String keyStr, String dataToSign) {
    try {

        Key key = getKey(algorithm, keyStr);

        JWSHeader.Builder jwsBuilder = new JWSHeader.Builder("HS256".equals(algorithm) ? JWSAlgorithm.HS256 : JWSAlgorithm.RS256);
        jwsBuilder.keyID(kid);

        JWSHeader signingHeader = jwsBuilder.build();
        JWSSigner signer = "HS256".equals(algorithm) ? new MACSigner(key.getEncoded()) : new RSASSASigner((RSAPrivateKey) key);
        JWSObject jwsObject = new JWSObject(signingHeader, new Payload(dataToSign));
        jwsObject.sign(signer);
        checkObject(jwsObject);

        String parts[] = jwsObject.serialize().split("\\.");

        return "{\"protected\":\"" + parts[0] + "\", \"payload\":\"" + parts[1] + "\", \"signature\":\"" + parts[2] + "\"}";

    } catch (Exception e) {
        throw new CryptoException("Exception signing data: " + e.getMessage(), e);
    }
}
 
開發者ID:americanexpress,項目名稱:amex-api-java-client-core,代碼行數:22,代碼來源:EncryptionUtility.java

示例7: createTokenRSA

public static String createTokenRSA( PrivateKey privateKey, String claimJson )
{
    try
    {
        JWSSigner signer = new RSASSASigner( ( RSAPrivateKey ) privateKey );

        Payload pl = new Payload( claimJson );
        JWSObject jwsObject = new JWSObject( new JWSHeader( JWSAlgorithm.RS256 ), pl );

        jwsObject.sign( signer );

        return jwsObject.serialize();
    }
    catch ( Exception e )
    {
        LOG.error( "Error creating RSA token", e.getMessage() );

        return "";
    }
}
 
開發者ID:subutai-io,項目名稱:base,代碼行數:20,代碼來源:TokenUtil.java

示例8: verifyTokenRSA

public static boolean verifyTokenRSA( PublicKey pKey, String token )
{
    try
    {
        Payload pl = new Payload( token );
        JWSObject jwsObject = new JWSObject( new JWSHeader( JWSAlgorithm.RS256 ), pl );
        JWSVerifier verifier = new RSASSAVerifier( ( RSAPublicKey ) pKey );

        return jwsObject.verify( verifier );
    }
    catch ( JOSEException e )
    {
        LOG.warn( "Error verifying RSA token", e.getMessage() );

        return false;
    }
}
 
開發者ID:subutai-io,項目名稱:base,代碼行數:17,代碼來源:TokenUtil.java

示例9: selfIssue

public String selfIssue() {
	JWSSigner signer = new RSASSASigner((RSAPrivateKey) keyPair.getPrivate());

	List<String> aud = new ArrayList<String>();
	aud.add(Constants.POYNT_API_HOST);

	JWTClaimsSet claimsSet = new JWTClaimsSet();
	claimsSet.setAudience(aud);
	claimsSet.setSubject(config.getAppId());
	claimsSet.setIssuer(config.getAppId());
	Calendar now = Calendar.getInstance();
	claimsSet.setIssueTime(now.getTime());
	now.add(Calendar.MINUTE, 15);
	claimsSet.setExpirationTime(now.getTime());
	claimsSet.setJWTID(UUID.randomUUID().toString());

	SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.RS256), claimsSet);

	try {
		signedJWT.sign(signer);
	} catch (JOSEException e) {
		throw new PoyntSdkException("Failed to sign self issued JWT.");
	}
	return signedJWT.serialize();
}
 
開發者ID:poynt,項目名稱:java-cloud-sdk,代碼行數:25,代碼來源:JsonWebToken.java

示例10: mapSignatureAlgorithm

/**
 * This method map signature algorithm define in identity.xml to nimbus
 * signature algorithm
 * format, Strings are defined inline hence there are not being used any
 * where
 *
 * @param signatureAlgorithm
 * @return
 * @throws IdentityOAuth2Exception
 */
protected JWSAlgorithm mapSignatureAlgorithm(String signatureAlgorithm) throws IdentityOAuth2Exception {

    if (NONE.equals(signatureAlgorithm)) {
        return new JWSAlgorithm(JWSAlgorithm.NONE.getName());
    } else if (SHA256_WITH_RSA.equals(signatureAlgorithm)) {
        return JWSAlgorithm.RS256;
    } else if (SHA384_WITH_RSA.equals(signatureAlgorithm)) {
        return JWSAlgorithm.RS384;
    } else if (SHA512_WITH_RSA.equals(signatureAlgorithm)) {
        return JWSAlgorithm.RS512;
    } else if (SHA256_WITH_HMAC.equals(signatureAlgorithm)) {
        return JWSAlgorithm.HS256;
    } else if (SHA384_WITH_HMAC.equals(signatureAlgorithm)) {
        return JWSAlgorithm.HS384;
    } else if (SHA512_WITH_HMAC.equals(signatureAlgorithm)) {
        return JWSAlgorithm.HS512;
    } else if (SHA256_WITH_EC.equals(signatureAlgorithm)) {
        return JWSAlgorithm.ES256;
    } else if (SHA384_WITH_EC.equals(signatureAlgorithm)) {
        return JWSAlgorithm.ES384;
    } else if (SHA512_WITH_EC.equals(signatureAlgorithm)) {
        return JWSAlgorithm.ES512;
    }
    throw new IdentityOAuth2Exception("Unsupported Signature Algorithm in identity.xml");
}
 
開發者ID:wso2,項目名稱:msf4j,代碼行數:35,代碼來源:JWTAccessTokenBuilder.java

示例11: mapSignatureAlgorithm

protected JWSAlgorithm mapSignatureAlgorithm(String signatureAlgorithm)
        throws IdentityOAuth2Exception {
    if ("SHA256withRSA".equals(signatureAlgorithm)) {
        return JWSAlgorithm.RS256;
    } else if ("SHA384withRSA".equals(signatureAlgorithm)) {
        return JWSAlgorithm.RS384;
    } else if ("SHA512withRSA".equals(signatureAlgorithm)) {
        return JWSAlgorithm.RS512;
    } else if ("SHA256withHMAC".equals(signatureAlgorithm)) {
        return JWSAlgorithm.HS256;
    } else if ("SHA384withHMAC".equals(signatureAlgorithm)) {
        return JWSAlgorithm.HS384;
    } else if ("SHA512withHMAC".equals(signatureAlgorithm)) {
        return JWSAlgorithm.HS512;
    } else if ("SHA256withEC".equals(signatureAlgorithm)) {
        return JWSAlgorithm.ES256;
    } else if ("SHA384withEC".equals(signatureAlgorithm)) {
        return JWSAlgorithm.ES384;
    } else if ("SHA512withEC".equals(signatureAlgorithm)) {
        return JWSAlgorithm.ES512;
    }
    log.error("Unsupported Signature Algorithm in identity.xml");
    throw new IdentityOAuth2Exception("Unsupported Signature Algorithm in identity.xml");
}
 
開發者ID:apache,項目名稱:stratos,代碼行數:24,代碼來源:ClientCredentialsGrantHandler.java

示例12: generateJWT

protected String generateJWT(User user) throws Exception {

        RSAPrivateKey privateKey = getPrivateKey(keyStore, keyStorePassword, alias);
        // Create RSA-signer with the private key
        JWSSigner signer = new RSASSASigner(privateKey);

        // Prepare JWT with claims set
        JWTClaimsSet claimsSet = new JWTClaimsSet();
        claimsSet.setSubject(user.getName());
        claimsSet.setClaim("email", user.getEmail());
        claimsSet.setClaim("roles", user.getRoles());
        claimsSet.setIssuer("wso2.org/products/msf4j");
        claimsSet.setExpirationTime(new Date(new Date().getTime() + 60 * 60 * 1000)); //60 min

        SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.RS256), claimsSet);

        // Compute the RSA signature
        signedJWT.sign(signer);

        // To serialize to compact form, produces something like
        // eyJhbGciOiJSUzI1NiJ9.SW4gUlNBIHdlIHRydXN0IQ.IRMQENi4nJyp4er2L
        // mZq3ivwoAjqa1uUkSBKFIX7ATndFF5ivnt-m8uApHO4kfIFOrW7w2Ezmlg3Qd
        // maXlS9DhN0nUk_hGI3amEjkKd0BWYCB8vfUbUv0XGjQip78AI4z1PrFRNidm7
        // -jPDm5Iq0SZnjKjCNS5Q15fokXZc8u0A

        return signedJWT.serialize();
    }
 
開發者ID:wso2,項目名稱:msf4j,代碼行數:27,代碼來源:JWTGenerator.java

示例13: createToken

private String createToken(String userName, Date expirationDate, PrivateKey signingKey) throws JOSEException, NoSuchAlgorithmException {
    JWTClaimsSet.Builder claimsSet = new JWTClaimsSet.Builder();

    claimsSet.subject("123445667");
    claimsSet.claim("username", userName);
    claimsSet.audience("resource-server");
    claimsSet.issuer("elytron.org");
    claimsSet.expirationTime(expirationDate);

    SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.RS256), claimsSet.build());

    signedJWT.sign(new RSASSASigner(signingKey));

    return signedJWT.serialize();
}
 
開發者ID:wildfly-security,項目名稱:elytron-web,代碼行數:15,代碼來源:BearerTokenAuthenticationTest.java

示例14: mapSignatureAlgorithm

/**
 * This method map signature algorithm define in identity.xml to nimbus
 * signature algorithm
 * format, Strings are defined inline hence there are not being used any
 * where
 *
 * @param signatureAlgorithm
 * @return
 * @throws IdentityOAuth2Exception
 */
protected JWSAlgorithm mapSignatureAlgorithm(String signatureAlgorithm)
        throws IdentityOAuth2Exception {
    if ("SHA256withRSA".equals(signatureAlgorithm)) {
        return JWSAlgorithm.RS256;
    } else if ("SHA384withRSA".equals(signatureAlgorithm)) {
        return JWSAlgorithm.RS384;
    } else if ("SHA512withRSA".equals(signatureAlgorithm)) {
        return JWSAlgorithm.RS512;
    } else if ("SHA256withHMAC".equals(signatureAlgorithm)) {
        return JWSAlgorithm.HS256;
    } else if ("SHA384withHMAC".equals(signatureAlgorithm)) {
        return JWSAlgorithm.HS384;
    } else if ("SHA512withHMAC".equals(signatureAlgorithm)) {
        return JWSAlgorithm.HS512;
    } else if ("SHA256withEC".equals(signatureAlgorithm)) {
        return JWSAlgorithm.ES256;
    } else if ("SHA384withEC".equals(signatureAlgorithm)) {
        return JWSAlgorithm.ES384;
    } else if ("SHA512withEC".equals(signatureAlgorithm)) {
        return JWSAlgorithm.ES512;
    } else if(NONE.equals(signatureAlgorithm)){
        return new JWSAlgorithm(JWSAlgorithm.NONE.getName());
    }
    log.error("Unsupported Signature Algorithm in identity.xml");
    throw new IdentityOAuth2Exception("Unsupported Signature Algorithm in identity.xml");
}
 
開發者ID:wso2-attic,項目名稱:carbon-identity,代碼行數:36,代碼來源:JWTTokenGenerator.java


注:本文中的com.nimbusds.jose.JWSAlgorithm.RS256屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。