0

我可以看到如何使用jose.4.jKey创建新的 s,但我想知道如何获取它们的数组并输出可公开访问的 JSON 列表,以用作 OiDC 中发现端点的一部分。像IETF 草案示例之类的东西......

 {"keys":
   [
     {"kty":"EC",
      "crv":"P-256",
      "x":"MKBCTNIcKUSDii11ySs3526iDZ8AiTo7Tu6KPAqv7D4",
      "y":"4Etl6SRW2YiLUrN5vfvVHuhp7x8PxltmWWlbbM4IFyM",
      "use":"enc",
      "kid":"1"},

     {"kty":"RSA",
      "n": "0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx
 4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMs
 tn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2
 QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbI
 SD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqb
 w0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw",
      "e":"AQAB",
      "alg":"RS256",
      "kid":"2011-04-29"}
   ]
 }

我想我缺少一些明显的东西toString(),比如不显示私钥的东西?

4

1 回答 1

3

有一种String toJson(JsonWebKey.OutputControlLevel outputControlLevel)方法,JsonWebKeySet在使用JsonWebKey.OutputControlLevel.PUBLIC_ONLY. 那应该给你你正在寻找的东西。JsonWebKeySet可以使用 JsonWebKeys 列表进行实例化。

例如,像这样的东西,

    RsaJsonWebKey rsaJwk1 = RsaJwkGenerator.generateJwk(2048);
    RsaJsonWebKey rsaJwk2 = RsaJwkGenerator.generateJwk(2048);
    EllipticCurveJsonWebKey ecJwk = EcJwkGenerator.generateJwk(EllipticCurves.P256);

    JsonWebKeySet jwks = new JsonWebKeySet(rsaJwk1, rsaJwk2, ecJwk);

    String jwksJson = jwks.toJson(JsonWebKey.OutputControlLevel.PUBLIC_ONLY);

    System.out.println(jwksJson);

会给,

{"keys":[{"kty":"RSA","n":"4cejS2CzkJuoLe9ry1JDdS_-RkpR2UMLialeH9WleuQFbFT3caK-GtNwObcd9_xEZ2H7um2GgZuscCMepo7d0FmwQUnfnTy9-_ckdgvVCH6lF62H3Jd4FBWAlcp_100kEJUe9YwfytdJ0zpOLo5Q38kH31cyMZmZRfexf33CzMNhlgE3mydpM9NAOAnR8IXW43tl1lPEy_dvLE9kM4idIjhd5Xd0a_YmRr05PK4UgFot0cuzZgu0HHe1qM7aFevwSOQ_Y86g4ofjZWHQWGJRN6WCBlGLscUwB52-hlJC0GrVEI0Cb55bfAfu01P1eFTjwyjfwggyLFZLdiAkZl2Jkw","e":"AQAB"},{"kty":"RSA","n":"jyOndkwyHBaHMn1xTIPfKV8PulJi6lcqqnw3sOabE-hClQr6De_OEcMnfCHPuogz1oep0A7-SvjY6Lclp0Pa5JDnHy6fI8UkSmASS6cwEUVWg18taFazRu2GtKDmMzT0Sh7ZCRGLWU74p5hRHGCerVnLcJUqSzT7kuGViZWVaIt00SfI6OImDpJTnaoxSwasdrhIZ_j5ARM93B2RKFsEb1kZ_gPnlP_0Qzs62LLG-78QQzlfMTd6v29vNr1FPPeZe744ni5Rpp19vEfEShGSV6Vz8K_Z2JlYC8PA_cRx47FLvmj9fB1u_wWYNP5ryGjv2E5Vjy9tqnIOmmtByoTdFw","e":"AQAB"},{"kty":"EC","x":"EEzQrpMmJ4XQgJFNGFNVI2WLmoaIpMYBTNF1_D5lp2U","y":"rENpzGhayZRoVR-7cFWJKElDQdJkJrKrDJ0-FqNpstA","crv":"P-256"}]}
于 2016-11-01T21:23:09.143 回答