com.nimbusds.jose.jwk.JWK.getKeyType()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(3.4k)|赞(0)|评价(0)|浏览(122)

本文整理了Java中com.nimbusds.jose.jwk.JWK.getKeyType()方法的一些代码示例,展示了JWK.getKeyType()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JWK.getKeyType()方法的具体详情如下:
包路径:com.nimbusds.jose.jwk.JWK
类名称:JWK
方法名:getKeyType

JWK.getKeyType介绍

[英]Gets the type ( kty) of this JWK.
[中]获取此JWK的类型(kty)。

代码示例

代码示例来源:origin: spring-projects/spring-security

@Test
public void getWhenMatchThenCreatesKeys() {
  when(this.matcher.matches(any())).thenReturn(true);
  List<JWK> keys = this.source.get(this.selector).block();
  assertThat(keys).hasSize(2);
  JWK key1 = keys.get(0);
  assertThat(key1.getKeyID()).isEqualTo("1923397381d9574bb873202a90c32b7ceeaed027");
  assertThat(key1.getAlgorithm().getName()).isEqualTo("RS256");
  assertThat(key1.getKeyType()).isEqualTo(KeyType.RSA);
  assertThat(key1.getKeyUse()).isEqualTo(KeyUse.SIGNATURE);
  JWK key2 = keys.get(1);
  assertThat(key2.getKeyID()).isEqualTo("7ddf54d3032d1f0d48c3618892ca74c1ac30ad77");
  assertThat(key2.getAlgorithm().getName()).isEqualTo("RS256");
  assertThat(key2.getKeyType()).isEqualTo(KeyType.RSA);
  assertThat(key2.getKeyUse()).isEqualTo(KeyUse.SIGNATURE);
}

代码示例来源:origin: de.adorsys.cryptoutils/jjwk

public static JWSAlgorithm getJWSAlgo(KeyAndJwk randomKey) {
  Algorithm algorithm = randomKey.jwk.getAlgorithm();
  if(algorithm!=null && (algorithm instanceof JWSAlgorithm)) return (JWSAlgorithm) algorithm;
  
  KeyType keyType = randomKey.jwk.getKeyType();
  if(keyType!=null){
    if(KeyType.RSA.equals(keyType)){
      return JWSAlgorithm.RS256;
    } else if(KeyType.EC.equals(keyType)){
      return JWSAlgorithm.ES256;
    } else if(KeyType.OCT.equals(keyType)){
      return JWSAlgorithm.HS256;
    } else {
      throw new IllegalStateException("Unknown key type: " + keyType);
    }
  } else {
    if(randomKey.jwk instanceof RSAKey){
      return JWSAlgorithm.RS256;
    } else if (randomKey.jwk instanceof ECKey){
      return JWSAlgorithm.ES256;
    } else if (randomKey.jwk instanceof OctetSequenceKey){
      return JWSAlgorithm.HS256;
    } else {
      throw new IllegalStateException("Unknown key type: " + randomKey.jwk.getClass().getName());				
    }
  }
}

代码示例来源:origin: com.nimbusds/nimbus-jose-jwt

return false;
if (types != null && ! types.contains(key.getKeyType()))
  return false;

代码示例来源:origin: io.gravitee.am.gateway.handlers/gravitee-am-gateway-handler

private JWK convert(com.nimbusds.jose.jwk.JWK jwk) {
  if (jwk == null) {
    return null;
  }
  switch (KeyType.valueOf(jwk.getKeyType().getValue())) {
    case EC:
      return fromEC((com.nimbusds.jose.jwk.ECKey) jwk);
    case RSA:
      return fromRSA((com.nimbusds.jose.jwk.RSAKey) jwk);
    case OCT:
      throw new NotImplementedException("JWK Key Type:" + KeyType.OCT.getKeyType());
    case OKP:
      throw new NotImplementedException("JWK Key Type:" + KeyType.OKP.getKeyType());
    default:
      throw new InvalidClientMetadataException("Unknown JWK Key Type (kty)");
  }
}

代码示例来源:origin: gravitee-io/graviteeio-access-management

private JWK convert(com.nimbusds.jose.jwk.JWK jwk) {
  if (jwk == null) {
    return null;
  }
  switch (KeyType.valueOf(jwk.getKeyType().getValue())) {
    case EC:
      return fromEC((com.nimbusds.jose.jwk.ECKey) jwk);
    case RSA:
      return fromRSA((com.nimbusds.jose.jwk.RSAKey) jwk);
    case OCT:
      throw new NotImplementedException("JWK Key Type:" + KeyType.OCT.getKeyType());
    case OKP:
      throw new NotImplementedException("JWK Key Type:" + KeyType.OKP.getKeyType());
    default:
      throw new InvalidClientMetadataException("Unknown JWK Key Type (kty)");
  }
}

代码示例来源:origin: gravitee-io/graviteeio-access-management

private JWK convert(com.nimbusds.jose.jwk.JWK nimbusJwk) {
  RSAKey jwk = new RSAKey();
  if (nimbusJwk.getKeyType() != null) {
    jwk.setKty(nimbusJwk.getKeyType().getValue());

相关文章