本文整理汇总了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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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()));
}