Examples of JWK


Examples of com.nimbusds.jose.jwk.JWK

  private void buildEncryptersAndDecrypters() throws NoSuchAlgorithmException, InvalidKeySpecException, JOSEException {

    for (Map.Entry<String, JWK> jwkEntry : keys.entrySet()) {

      String id = jwkEntry.getKey();
      JWK jwk = jwkEntry.getValue();

      if (jwk instanceof RSAKey) {
        // build RSA encrypters and decrypters

        RSAEncrypter encrypter = new RSAEncrypter(((RSAKey) jwk).toRSAPublicKey()); // there should always at least be the public key
        encrypters.put(id, encrypter);

        if (jwk.isPrivate()) { // we can decrypt!
          RSADecrypter decrypter = new RSADecrypter(((RSAKey) jwk).toRSAPrivateKey());
          decrypters.put(id, decrypter);
        } else {
          logger.warn("No private key for key #" + jwk.getKeyID());
        }

        // TODO: add support for EC keys

      } else if (jwk instanceof OctetSequenceKey) {
View Full Code Here

Examples of com.nimbusds.jose.jwk.JWK

  public Map<String, JWK> getAllPublicKeys() {
    Map<String, JWK> pubKeys = new HashMap<String, JWK>();

    // pull out all public keys
    for (String keyId : keys.keySet()) {
      JWK key = keys.get(keyId);
      JWK pub = key.toPublicJWK();
      if (pub != null) {
        pubKeys.put(keyId, pub);
      }
    }
View Full Code Here

Examples of com.nimbusds.jose.jwk.JWK

   */
  private void buildSignersAndVerifiers() throws NoSuchAlgorithmException, InvalidKeySpecException {
    for (Map.Entry<String, JWK> jwkEntry : keys.entrySet()) {

      String id = jwkEntry.getKey();
      JWK jwk = jwkEntry.getValue();

      if (jwk instanceof RSAKey) {
        // build RSA signers & verifiers

        if (jwk.isPrivate()) { // only add the signer if there's a private key
          RSASSASigner signer = new RSASSASigner(((RSAKey) jwk).toRSAPrivateKey());
          signers.put(id, signer);
        }

        RSASSAVerifier verifier = new RSASSAVerifier(((RSAKey) jwk).toRSAPublicKey());
        verifiers.put(id, verifier);

      } else if (jwk instanceof ECKey) {
        // build EC signers & verifiers

        // TODO: add support for EC keys
        logger.warn("EC Keys are not yet supported.");

      } else if (jwk instanceof OctetSequenceKey) {
        // build HMAC signers & verifiers

        if (jwk.isPrivate()) { // technically redundant check because all HMAC keys are private
          MACSigner signer = new MACSigner(((OctetSequenceKey) jwk).toByteArray());
          signers.put(id, signer);
        }

        MACVerifier verifier = new MACVerifier(((OctetSequenceKey) jwk).toByteArray());
View Full Code Here

Examples of com.nimbusds.jose.jwk.JWK

  public Map<String, JWK> getAllPublicKeys() {
    Map<String, JWK> pubKeys = new HashMap<String, JWK>();

    // pull all keys out of the verifiers if we know how
    for (String keyId : keys.keySet()) {
      JWK key = keys.get(keyId);
      JWK pub = key.toPublicJWK();
      if (pub != null) {
        pubKeys.put(keyId, pub);
      }
    }
View Full Code Here

Examples of com.nimbusds.jose.jwk.JWK

    public JwtSigningAndValidationService load(String key) throws Exception {
      try {

        String id = "SYMMETRIC-KEY";

        JWK jwk = new OctetSequenceKey(Base64URL.encode(key), KeyUse.SIGNATURE, null, null, id, null, null, null);
        Map<String, JWK> keys = ImmutableMap.of(id, jwk);
        JwtSigningAndValidationService service = new DefaultJwtSigningAndValidationService(keys);

        return service;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.