本文整理汇总了Java中org.jose4j.base64url.Base64Url类的典型用法代码示例。如果您正苦于以下问题:Java Base64Url类的具体用法?Java Base64Url怎么用?Java Base64Url使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Base64Url类属于org.jose4j.base64url包,在下文中一共展示了Base64Url类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deriveForEncrypt
import org.jose4j.base64url.Base64Url; //导入依赖的package包/类
protected Key deriveForEncrypt(Key managementKey, Headers headers, ProviderContext providerContext) throws JoseException
{
Long iterationCount = headers.getLongHeaderValue(HeaderParameterNames.PBES2_ITERATION_COUNT);
if (iterationCount == null)
{
iterationCount = defaultIterationCount;
headers.setObjectHeaderValue(HeaderParameterNames.PBES2_ITERATION_COUNT, iterationCount);
}
String saltInputString = headers.getStringHeaderValue(HeaderParameterNames.PBES2_SALT_INPUT);
byte[] saltInput;
Base64Url base64Url = new Base64Url();
if (saltInputString == null)
{
saltInput = ByteUtil.randomBytes(defaultSaltByteLength, providerContext.getSecureRandom());
saltInputString = base64Url.base64UrlEncode(saltInput);
headers.setStringHeaderValue(HeaderParameterNames.PBES2_SALT_INPUT, saltInputString);
}
else
{
saltInput = base64Url.base64UrlDecode(saltInputString);
}
return deriveKey(managementKey, iterationCount, saltInput, providerContext);
}
示例2: testSomeDataCompressedElsewhere
import org.jose4j.base64url.Base64Url; //导入依赖的package包/类
public void testSomeDataCompressedElsewhere() throws JoseException
{
String s ="q1bKLC5WslLKKCkpKLaK0Y/Rz0wp0EutSMwtyEnVS87PVdLhUkqtKFCyMjQ2NTcyNTW3sACKJJamoGgqRujJL0o" +
"H6ckqyQSqKMmNLIsMCzWqsPAp8zM3cjINjHdNTPbQizd1BClKTC4CKjICMYtLk4BMp6LMxDylWi4A";
byte[] decoded = Base64Url.decode(s);
CompressionAlgorithm ca = new DeflateRFC1951CompressionAlgorithm();
byte[] decompress = ca.decompress(decoded);
String decompedString = StringUtil.newStringUtf8(decompress);
String expected = "{\"iss\":\"https:\\/\\/idp.example.com\",\n" +
"\"exp\":1357255788,\n" +
"\"aud\":\"https:\\/\\/sp.example.org\",\n" +
"\"jti\":\"tmYvYVU2x8LvN72B5Q_EacH._5A\",\n" +
"\"acr\":\"2\",\n" +
"\"sub\":\"Brian\"}\n";
assertEquals(expected, decompedString);
}
示例3: testNpeWithNonExtractableKeyDataHS256
import org.jose4j.base64url.Base64Url; //导入依赖的package包/类
@Test
public void testNpeWithNonExtractableKeyDataHS256() throws Exception
{
byte[] raw = Base64Url.decode("hup76LcA9B7pqrEtqyb4EBg6XCcr9r0iOCFF1FeZiJM");
FakeHsmNonExtractableSecretKeySpec key = new FakeHsmNonExtractableSecretKeySpec(raw, "HmacSHA256");
JwtClaims claims = new JwtClaims();
claims.setExpirationTimeMinutesInTheFuture(5);
claims.setSubject("subject");
claims.setIssuer("issuer");
JsonWebSignature jws = new JsonWebSignature();
jws.setPayload(claims.toJson());
jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.HMAC_SHA256);
jws.setKey(key);
String jwt = jws.getCompactSerialization();
JwtConsumerBuilder jwtConsumerBuilder = new JwtConsumerBuilder();
jwtConsumerBuilder.setAllowedClockSkewInSeconds(60);
jwtConsumerBuilder.setRequireSubject();
jwtConsumerBuilder.setExpectedIssuer("issuer");
jwtConsumerBuilder.setVerificationKey(key);
JwtConsumer jwtConsumer = jwtConsumerBuilder.build();
JwtClaims processedClaims = jwtConsumer.processToClaims(jwt);
System.out.println(processedClaims);
}
示例4: littleJweRoundTrip
import org.jose4j.base64url.Base64Url; //导入依赖的package包/类
private void littleJweRoundTrip(String alg, String enc, String b64uKey) throws Exception
{
byte[] raw = Base64Url.decode(b64uKey);
Key key = new FakeHsmNonExtractableSecretKeySpec(raw, "AES");
JwtClaims claims = new JwtClaims();
claims.setExpirationTimeMinutesInTheFuture(5);
claims.setSubject("subject");
claims.setIssuer("issuer");
JsonWebEncryption jwe = new JsonWebEncryption();
jwe.setPayload(claims.toJson());
jwe.setAlgorithmHeaderValue(alg);
jwe.setEncryptionMethodHeaderParameter(enc);
jwe.setKey(key);
String jwt = jwe.getCompactSerialization();
JwtConsumerBuilder jwtConsumerBuilder = new JwtConsumerBuilder();
jwtConsumerBuilder.setAllowedClockSkewInSeconds(60);
jwtConsumerBuilder.setRequireSubject();
jwtConsumerBuilder.setExpectedIssuer("issuer");
jwtConsumerBuilder.setDecryptionKey(key);
jwtConsumerBuilder.setDisableRequireSignature();
JwtConsumer jwtConsumer = jwtConsumerBuilder.build();
JwtClaims processedClaims = jwtConsumer.processToClaims(jwt);
Assert.assertThat(processedClaims.getSubject(), equalTo("subject"));
}
示例5: testExampleDecryptFromJweAppendix2
import org.jose4j.base64url.Base64Url; //导入依赖的package包/类
public void testExampleDecryptFromJweAppendix2() throws JoseException
{
int[] ints = {4, 211, 31, 197, 84, 157, 252, 254, 11, 100, 157, 250, 63, 170, 106, 206, 107, 124, 212, 45, 111, 107, 9, 219, 200, 177, 0, 240, 143, 156, 44, 207};
byte[] contentEncryptionKeyBytes = ByteUtil.convertUnsignedToSignedTwosComp(ints);
Base64Url b = new Base64Url();
String encodedHeader = "eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0";
Headers headers = new Headers();
headers.setFullHeaderAsJsonString(Base64Url.decodeToUtf8String(encodedHeader));
byte[] header = StringUtil.getBytesUtf8(encodedHeader);
byte[] iv = b.base64UrlDecode("AxY8DCtDaGlsbGljb3RoZQ");
byte[] ciphertext = b.base64UrlDecode("KDlTtXchhZTGufMYmOYGS4HffxPSUrfmqCHXaI9wOGY");
byte[] tag = b.base64UrlDecode("9hH0vgRfYgPnAHOd8stkvw");
AesCbcHmacSha2ContentEncryptionAlgorithm.Aes128CbcHmacSha256 jweContentEncryptionAlg = new AesCbcHmacSha2ContentEncryptionAlgorithm.Aes128CbcHmacSha256();
ContentEncryptionParts encryptionParts = new ContentEncryptionParts(iv, ciphertext, tag);
byte[] plaintextBytes = jweContentEncryptionAlg.decrypt(encryptionParts, header, contentEncryptionKeyBytes, headers, ProviderContextTest.EMPTY_CONTEXT);
assertEquals("Live long and prosper.", StringUtil.newStringUtf8(plaintextBytes));
}
示例6: testRoundTrip
import org.jose4j.base64url.Base64Url; //导入依赖的package包/类
public void testRoundTrip() throws JoseException
{
String text = "I'm writing this test on a flight to Zurich";
String encodedHeader = "eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0";
Headers headers = new Headers();
headers.setFullHeaderAsJsonString(Base64Url.decodeToUtf8String(encodedHeader));
byte[] aad = StringUtil.getBytesUtf8(encodedHeader);
byte[] plaintext = StringUtil.getBytesUtf8(text);
AesCbcHmacSha2ContentEncryptionAlgorithm.Aes128CbcHmacSha256 contentEncryptionAlg = new AesCbcHmacSha2ContentEncryptionAlgorithm.Aes128CbcHmacSha256();
ContentEncryptionKeyDescriptor cekDesc = contentEncryptionAlg.getContentEncryptionKeyDescriptor();
byte[] cek = ByteUtil.randomBytes(cekDesc.getContentEncryptionKeyByteLength());
ContentEncryptionParts encryptionParts = contentEncryptionAlg.encrypt(plaintext, aad, cek, headers, null, ProviderContextTest.EMPTY_CONTEXT);
byte[] decrypt = contentEncryptionAlg.decrypt(encryptionParts, aad, cek, null, ProviderContextTest.EMPTY_CONTEXT);
assertEquals(text, StringUtil.newStringUtf8(decrypt));
}
示例7: testKdf1
import org.jose4j.base64url.Base64Url; //导入依赖的package包/类
public void testKdf1() throws Exception
{
// test values produced from implementation found at http://stackoverflow.com/questions/10879658
String derivedKey = "pgs50IOZ6BxfqvTSie4t9OjWxGr4whiHo1v9Dti93CRiJE2PP60FojLatVVrcjg3BxpuFjnlQxL97GOwAfcwLA";
byte[] z = Base64Url.decode("Sq8rGLm4rEtzScmnSsY5r1n-AqBl_iBU8FxN80Uc0S0");
System.out.println(Base64Url.encode(z));
KdfUtil kdfUtil = new KdfUtil();
int keyDatalen = 512;
String alg = ContentEncryptionAlgorithmIdentifiers.AES_256_CBC_HMAC_SHA_512;
byte[] algId = kdfUtil.prependDatalen(StringUtil.getBytesUtf8(alg));
byte[] partyU = new byte[] {0, 0, 0, 0};
byte[] partyV = new byte[] {0, 0, 0, 0};
byte[] pub = ByteUtil.getBytes(keyDatalen);
byte[] priv = ByteUtil.EMPTY_BYTES;
ConcatKeyDerivationFunction myConcatKdf = new ConcatKeyDerivationFunction("SHA-256", null);
byte[] kdfed = myConcatKdf.kdf(z, keyDatalen, algId, partyU, partyV, pub, priv);
assertEquals(derivedKey, Base64Url.encode(kdfed));
}
示例8: testKdf2
import org.jose4j.base64url.Base64Url; //导入依赖的package包/类
public void testKdf2() throws Exception
{
// test values produced from implementation found at http://stackoverflow.com/questions/10879658
String derivedKey = "vphyobtvExGXF7TaOvAkx6CCjHQNYamP2ET8xkhTu-0";
byte[] z = Base64Url.decode("LfkHot2nGTVlmfxbgxQfMg"); // ByteUtil.randomBytes(16);
System.out.println(Base64Url.encode(z));
KdfUtil kdfUtil = new KdfUtil(null);
int keyDatalen = 256;
String alg = ContentEncryptionAlgorithmIdentifiers.AES_128_CBC_HMAC_SHA_256;
byte[] algId = kdfUtil.prependDatalen(StringUtil.getBytesUtf8(alg));
byte[] partyU = new byte[] {0, 0, 0, 0};
byte[] partyV = new byte[] {0, 0, 0, 0};
byte[] pub = ByteUtil.getBytes(keyDatalen);
byte[] priv = ByteUtil.EMPTY_BYTES;
ConcatKeyDerivationFunction myConcatKdf = new ConcatKeyDerivationFunction("SHA-256", null);
byte[] kdfed = myConcatKdf.kdf(z, keyDatalen, algId, partyU, partyV, pub, priv);
assertEquals(derivedKey, Base64Url.encode(kdfed));
}
示例9: testKdf3
import org.jose4j.base64url.Base64Url; //导入依赖的package包/类
public void testKdf3() throws Exception
{
// test values produced from implementation found at http://stackoverflow.com/questions/10879658
String derivedKey = "yRbmmZJpxv3H1aq3FgzESa453frljIaeMz6pt5rQZ4Q5Hs-4RYoFRXFh_qBsbTjlsj8JxIYTWj-cp5LKtgi1fBRsf_5yTEcLDv4pKH2fNxjbEOKuVVDWA1_Qv2IkEC0_QSi3lSSELcJaNX-hDG8occ7oQv-w8lg6lLJjg58kOes";
byte[] z = Base64Url.decode("KSDnQpf2iurUsAbcuI4YH-FKfk2gecN6cWHTYlBzrd8");
KdfUtil kdfUtil = new KdfUtil(null);
int keyDatalen = 1024;
String alg = "meh";
byte[] algId = kdfUtil.prependDatalen(StringUtil.getBytesUtf8(alg));
byte[] partyU = new byte[] {0, 0, 0, 5, 65, 108, 105, 99, 101};
byte[] partyV = new byte[] {0, 0, 0, 3, 66, 111, 98};
byte[] pub = ByteUtil.getBytes(keyDatalen);
byte[] priv = ByteUtil.EMPTY_BYTES;
ConcatKeyDerivationFunction myConcatKdf = new ConcatKeyDerivationFunction("SHA-256");
byte[] kdfed = myConcatKdf.kdf(z, keyDatalen, algId, partyU, partyV, pub, priv);
assertEquals(derivedKey, Base64Url.encode(kdfed));
}
示例10: testKdf4
import org.jose4j.base64url.Base64Url; //导入依赖的package包/类
public void testKdf4() throws Exception
{
// test values produced from implementation found at http://stackoverflow.com/questions/10879658
String derivedKey = "SNOvl6h5iSYWJ_EhlnvK8o6om9iyR8HkKMQtQYGkYKkVY0HFMleoUm-H6-kLz8sW";
byte[] z = Base64Url.decode("zp9Hot2noTVlmfxbkXqfn1");
KdfUtil kdfUtil = new KdfUtil();
int keyDatalen = 384;
String alg = ContentEncryptionAlgorithmIdentifiers.AES_192_CBC_HMAC_SHA_384;
byte[] algId = kdfUtil.prependDatalen(StringUtil.getBytesUtf8(alg));
byte[] partyU = new byte[] {0, 0, 0, 0};
byte[] partyV = new byte[] {0, 0, 0, 0};
byte[] pub = ByteUtil.getBytes(keyDatalen);
byte[] priv = ByteUtil.EMPTY_BYTES;
ConcatKeyDerivationFunction myConcatKdf = new ConcatKeyDerivationFunction("SHA-256");
byte[] kdfed = myConcatKdf.kdf(z, keyDatalen, algId, partyU, partyV, pub, priv);
assertEquals(derivedKey, Base64Url.encode(kdfed));
}
示例11: testDefaultsMeetMinimumRequiredOrSuggested
import org.jose4j.base64url.Base64Url; //导入依赖的package包/类
@Test
public void testDefaultsMeetMinimumRequiredOrSuggested() throws JoseException
{
JsonWebEncryption encryptingJwe = new JsonWebEncryption();
encryptingJwe.setAlgorithmHeaderValue(PBES2_HS256_A128KW);
encryptingJwe.setEncryptionMethodHeaderParameter(AES_128_CBC_HMAC_SHA_256);
encryptingJwe.setPayload("meh");
PbkdfKey key = new PbkdfKey("passtheword");
encryptingJwe.setKey(key);
String compactSerialization = encryptingJwe.getCompactSerialization();
System.out.println(compactSerialization);
JsonWebEncryption decryptingJwe = new JsonWebEncryption();
decryptingJwe.setCompactSerialization(compactSerialization);
decryptingJwe.setKey(key);
decryptingJwe.getPayload();
Headers headers = decryptingJwe.getHeaders();
Long iterationCount = headers.getLongHeaderValue(HeaderParameterNames.PBES2_ITERATION_COUNT);
assertTrue(iterationCount >= MINIMUM_ITERAION_COUNT);
String saltInputString = headers.getStringHeaderValue(HeaderParameterNames.PBES2_SALT_INPUT);
Base64Url b = new Base64Url();
byte[] saltInput = b.base64UrlDecode(saltInputString);
assertTrue(saltInput.length >= MINIMUM_SALT_BYTE_LENGTH);
}
示例12: testJweExampleA2
import org.jose4j.base64url.Base64Url; //导入依赖的package包/类
public void testJweExampleA2() throws JoseException
{
String encodedEncryptedKey =
"UGhIOguC7IuEvf_NPVaXsGMoLOmwvc1GyqlIKOK1nN94nHPoltGRhWhw7Zx0-kFm" +
"1NJn8LE9XShH59_i8J0PH5ZZyNfGy2xGdULU7sHNF6Gp2vPLgNZ__deLKxGHZ7Pc" +
"HALUzoOegEI-8E66jX2E4zyJKx-YxzZIItRzC5hlRirb6Y5Cl_p-ko3YvkkysZIF" +
"NPccxRU7qve1WYPxqbb2Yw8kZqa2rMWI5ng8OtvzlV7elprCbuPhcCdZ6XDP0_F8" +
"rkXds2vE4X-ncOIM8hAYHHi29NX0mcKiRaD0-D-ljQTP-cFPgwCp6X-nZZd9OHBv" +
"-B3oWh2TbqmScqXMR4gp_A";
Base64Url base64Url = new Base64Url();
byte[] encryptedKey = base64Url.base64UrlDecode(encodedEncryptedKey);
RsaKeyManagementAlgorithm.Rsa1_5 keyManagementAlgorithm = new RsaKeyManagementAlgorithm.Rsa1_5();
PrivateKey privateKey = ExampleRsaJwksFromJwe.APPENDIX_A_2.getPrivateKey();
ContentEncryptionAlgorithm contentEncryptionAlgorithm = new AesCbcHmacSha2ContentEncryptionAlgorithm.Aes128CbcHmacSha256();
ContentEncryptionKeyDescriptor cekDesc = contentEncryptionAlgorithm.getContentEncryptionKeyDescriptor();
Key key = keyManagementAlgorithm.manageForDecrypt(privateKey, encryptedKey, cekDesc, null, ProviderContextTest.EMPTY_CONTEXT);
byte[] cekBytes = ByteUtil.convertUnsignedToSignedTwosComp(new int[]{4, 211, 31, 197, 84, 157, 252, 254, 11, 100, 157, 250, 63, 170, 106,
206, 107, 124, 212, 45, 111, 107, 9, 219, 200, 177, 0, 240, 143, 156,
44, 207});
byte[] encoded = key.getEncoded();
assertTrue(Arrays.toString(encoded), Arrays.equals(cekBytes, encoded));
}
示例13: updateSession
import org.jose4j.base64url.Base64Url; //导入依赖的package包/类
@Override
public void updateSession(Session session) {
assertConnectionIsOpen();
String nonceHeader = conn.getHeaderField(REPLAY_NONCE_HEADER);
if (nonceHeader == null || nonceHeader.trim().isEmpty()) {
return;
}
if (!BASE64URL_PATTERN.matcher(nonceHeader).matches()) {
throw new AcmeProtocolException("Invalid replay nonce: " + nonceHeader);
}
LOG.debug("Replay Nonce: {}", nonceHeader);
session.setNonce(Base64Url.decode(nonceHeader));
}
示例14: main
import org.jose4j.base64url.Base64Url; //导入依赖的package包/类
/**
* Generates a new keypair for unit tests, and return its N, E, KTY and THUMBPRINT
* parameters to be set in the {@link TestUtils} class.
*/
public static void main(String... args) throws Exception {
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
keyGen.initialize(2048);
KeyPair keyPair = keyGen.generateKeyPair();
try (FileOutputStream out = new FileOutputStream("public.key")) {
out.write(keyPair.getPublic().getEncoded());
}
try (FileOutputStream out = new FileOutputStream("private.key")) {
out.write(keyPair.getPrivate().getEncoded());
}
final JsonWebKey jwk = JsonWebKey.Factory.newJwk(keyPair.getPublic());
Map<String, Object> params = new TreeMap<>(jwk.toParams(OutputControlLevel.PUBLIC_ONLY));
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(JsonUtil.toJson(params).getBytes("UTF-8"));
byte[] thumbprint = md.digest();
System.out.println("N = " + params.get("n"));
System.out.println("E = " + params.get("e"));
System.out.println("KTY = " + params.get("kty"));
System.out.println("THUMBPRINT = " + Base64Url.encode(thumbprint));
}
示例15: getCollectionContent
import org.jose4j.base64url.Base64Url; //导入依赖的package包/类
/**
* Retrieves this collection's information from Livefyre. Makes an external API call.
*
* @return JSONObject.
*/
public JsonObject getCollectionContent() {
String b64articleId = Base64Url.encode(data.getArticleId().getBytes());
if (b64articleId.length() % 4 != 0) {
b64articleId = b64articleId + StringUtils.repeat("=", 4 - (b64articleId.length() % 4));
}
String url = String.format("%s/bs3/%s.fyre.co/%s/%s/init", Domain.bootstrap(this), site.getNetwork().getNetworkName(), site.getData().getId(), b64articleId);
ClientResponse response = Client.create().resource(url).accept(MediaType.APPLICATION_JSON)
.get(ClientResponse.class);
if (response.getStatus() >= 400) {
throw new ApiException(response.getStatus());
}
Gson gson = new Gson();
return gson.fromJson(response.getEntity(String.class), JsonObject.class);
}