当前位置: 首页>>代码示例>>Java>>正文


Java JsonWebKey.getKey方法代码示例

本文整理汇总了Java中org.jose4j.jwk.JsonWebKey.getKey方法的典型用法代码示例。如果您正苦于以下问题:Java JsonWebKey.getKey方法的具体用法?Java JsonWebKey.getKey怎么用?Java JsonWebKey.getKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jose4j.jwk.JsonWebKey的用法示例。


在下文中一共展示了JsonWebKey.getKey方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: prepareJsonWebTokenKey

import org.jose4j.jwk.JsonWebKey; //导入方法依赖的package包/类
/**
 * Prepare json web token key.
 *
 * @param secret the secret
 * @return the key
 */
private Key prepareJsonWebTokenKey(final String secret) {

    try {
        final Map<String, Object> keys = new HashMap<>(2);
        keys.put("kty", "oct");
        keys.put("k", secret);
        final JsonWebKey jwk = JsonWebKey.Factory.newJwk(keys);
        return jwk.getKey();
    } catch (final Exception e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:19,代码来源:BaseStringCipherExecutor.java

示例2: prepareJsonWebTokenKey

import org.jose4j.jwk.JsonWebKey; //导入方法依赖的package包/类
/**
 * Prepare json web token key.
 *
 * @param secret the secret
 * @return the key
 */
private Key prepareJsonWebTokenKey(final String secret) {
    try {
        final Map<String, Object> keys = new HashMap<>(2);
        keys.put("kty", "oct");
        keys.put("k", secret);
        final JsonWebKey jwk = JsonWebKey.Factory.newJwk(keys);
        return jwk.getKey();
    } catch (final Exception e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:18,代码来源:DefaultCipherExecutor.java

示例3: prepareJsonWebTokenKey

import org.jose4j.jwk.JsonWebKey; //导入方法依赖的package包/类
/**
 * Prepare json web token key.
 *
 * @param secret the secret
 * @return the key
 */
private static Key prepareJsonWebTokenKey(final String secret) {
    try {
        final Map<String, Object> keys = new HashMap<>(2);
        keys.put("kty", "oct");
        keys.put(EncodingUtils.JSON_WEB_KEY, secret);
        final JsonWebKey jwk = JsonWebKey.Factory.newJwk(keys);
        return jwk.getKey();
    } catch (final Exception e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:18,代码来源:BaseStringCipherExecutor.java

示例4: manageForDecrypt

import org.jose4j.jwk.JsonWebKey; //导入方法依赖的package包/类
public Key manageForDecrypt(Key managementKey, byte[] encryptedKey, ContentEncryptionKeyDescriptor cekDesc, Headers headers,  ProviderContext providerContext) throws JoseException
{
    String keyFactoryProvider = providerContext.getGeneralProviderContext().getKeyFactoryProvider();
    JsonWebKey ephemeralJwk = headers.getPublicJwkHeaderValue(HeaderParameterNames.EPHEMERAL_PUBLIC_KEY, keyFactoryProvider);
    ephemeralJwk.getKey();
    byte[] z = generateEcdhSecret((PrivateKey) managementKey, (PublicKey)ephemeralJwk.getKey(), providerContext);
    byte[] derivedKey = kdf(cekDesc, headers, z, providerContext);
    String cekAlg = cekDesc.getContentEncryptionKeyAlgorithm();
    return new SecretKeySpec(derivedKey, cekAlg);
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:11,代码来源:EcdhKeyAgreementAlgorithm.java

示例5: testExamplesFromDraftEvenWithoutDirectSupportForTheHeader

import org.jose4j.jwk.JsonWebKey; //导入方法依赖的package包/类
@Test
public void testExamplesFromDraftEvenWithoutDirectSupportForTheHeader() throws Exception
{
    // a test of sorts to verify the examples from
    // http://tools.ietf.org/html/draft-ietf-jose-jws-signing-input-options-09#section-4
    // at Mike's request

    String jwkJson =
            "{" +
            "  \"kty\":\"oct\"," +
            "  \"k\":\"AyM1SysPpbyDfgZld3umj1qzKObwVMkoqQ-EstJQLr_T-1qS0gZH75" +
            "      aKtMN3Yj0iPS4hcgUuTwjAzZr1Z9CAow\"" +
            "}";
    final JsonWebKey jsonWebKey = JsonWebKey.Factory.newJwk(jwkJson);
    final Key key = jsonWebKey.getKey();

    String payload = "$.02";

    final String encodedPayload = Base64Url.encode(payload, StringUtil.US_ASCII);
    assertThat(encodedPayload, equalTo("JC4wMg"));

    String jwscsWithB64 = "eyJhbGciOiJIUzI1NiJ9.JC4wMg.5mvfOroL-g7HyqJoozehmsaqmvTYGEq5jTI1gVvoEoQ";

    JsonWebSignature jws = new JsonWebSignature();
    jws.setCompactSerialization(jwscsWithB64);
    jws.setKey(key);
    assertThat(jws.getPayload(), equalTo(payload));
    assertTrue(jws.verifySignature());

    jws = new JsonWebSignature();
    jws.setPayload(payload);
    jws.setKey(key);
    jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.HMAC_SHA256);
    assertThat(jws.getCompactSerialization(), equalTo(jwscsWithB64));

    String jwscsWithoutB64andDetachedPaylod = "eyJhbGciOiJIUzI1NiIsImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19.." +
            "A5dxf2s96_n5FLueVuW1Z_vh161FwXZC4YLPff6dmDY";

    jws = new JsonWebSignature();
    jws.setCompactSerialization(jwscsWithoutB64andDetachedPaylod);
    assertThat(jws.getHeaders().getFullHeaderAsJsonString(), equalTo("{\"alg\":\"HS256\",\"b64\":false,\"crit\":[\"b64\"]}"));

    HmacUsingShaAlgorithm.HmacSha256 hmacSha256 = new HmacUsingShaAlgorithm.HmacSha256();

    final String signingInputString = jws.getHeaders().getEncodedHeader() + "." + payload;

    final byte[] signatureBytes = Base64Url.decode(jws.getEncodedSignature());
    final byte[] securedInputBytes = StringUtil.getBytesAscii(signingInputString);
    final ProviderContext providerContext = new ProviderContext();
    boolean okay = hmacSha256.verifySignature(signatureBytes, key, securedInputBytes, providerContext);
    assertTrue(okay);

    final byte[] signed = hmacSha256.sign(key, securedInputBytes, providerContext);
    assertThat(Base64Url.encode(signed), equalTo(jws.getEncodedSignature()));
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:56,代码来源:JwsUnencodedPayloadOptionTest.java


注:本文中的org.jose4j.jwk.JsonWebKey.getKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。