本文整理汇总了Java中org.jose4j.base64url.Base64Url.encode方法的典型用法代码示例。如果您正苦于以下问题:Java Base64Url.encode方法的具体用法?Java Base64Url.encode怎么用?Java Base64Url.encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jose4j.base64url.Base64Url
的用法示例。
在下文中一共展示了Base64Url.encode方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: base64urlThumbprint
import org.jose4j.base64url.Base64Url; //导入方法依赖的package包/类
private static String base64urlThumbprint(X509Certificate certificate, String hashAlg)
{
MessageDigest msgDigest = HashUtil.getMessageDigest(hashAlg);
byte[] certificateEncoded;
try
{
certificateEncoded = certificate.getEncoded();
}
catch (CertificateEncodingException e)
{
throw new UncheckedJoseException("Unable to get certificate thumbprint due to unexpected certificate encoding exception.", e);
}
byte[] digest = msgDigest.digest(certificateEncoded);
return Base64Url.encode(digest);
}
示例3: testSettingSaltAndIterationCount
import org.jose4j.base64url.Base64Url; //导入方法依赖的package包/类
@Test
public void testSettingSaltAndIterationCount() throws JoseException
{
String password = "secret word";
String plaintext = "<insert some witty quote or remark here, again>";
JsonWebEncryption encryptingJwe = new JsonWebEncryption();
int saltByteLength = 32;
String saltInputString = Base64Url.encode(ByteUtil.randomBytes(saltByteLength));
encryptingJwe.getHeaders().setStringHeaderValue(HeaderParameterNames.PBES2_SALT_INPUT, saltInputString);
long iterationCount = 1024L;
encryptingJwe.getHeaders().setObjectHeaderValue(HeaderParameterNames.PBES2_ITERATION_COUNT, iterationCount);
encryptingJwe.setAlgorithmHeaderValue(PBES2_HS384_A192KW);
encryptingJwe.setEncryptionMethodHeaderParameter(AES_192_CBC_HMAC_SHA_384);
encryptingJwe.setPayload(plaintext);
encryptingJwe.setKey(new PbkdfKey(password));
String compactSerialization = encryptingJwe.getCompactSerialization();
JsonWebEncryption decryptingJwe = new JsonWebEncryption();
decryptingJwe.setCompactSerialization(compactSerialization);
decryptingJwe.setKey(new PbkdfKey(password));
assertThat(plaintext, equalTo(decryptingJwe.getPayload()));
String saltInputStringFromHeader = decryptingJwe.getHeader(HeaderParameterNames.PBES2_SALT_INPUT);
assertThat(saltInputString, equalTo(saltInputStringFromHeader));
assertThat(saltByteLength, equalTo(Base64Url.decode(saltInputStringFromHeader).length));
long iterationCountFromHeader = decryptingJwe.getHeaders().getLongHeaderValue(HeaderParameterNames.PBES2_ITERATION_COUNT);
assertThat(iterationCount, equalTo(iterationCountFromHeader));
}
示例4: getEncoded
import org.jose4j.base64url.Base64Url; //导入方法依赖的package包/类
private String getEncoded()
{
return Base64Url.encode(octetSequence);
}
示例5: calculateBase64urlEncodedThumbprint
import org.jose4j.base64url.Base64Url; //导入方法依赖的package包/类
public String calculateBase64urlEncodedThumbprint(String hashAlgorithm)
{
byte[] thumbprint = calculateThumbprint(hashAlgorithm);
return Base64Url.encode(thumbprint);
}
示例6: setGeneratedJwtId
import org.jose4j.base64url.Base64Url; //导入方法依赖的package包/类
public void setGeneratedJwtId(int numberOfBytes)
{
byte[] rndbytes = ByteUtil.randomBytes(numberOfBytes);
String jti = Base64Url.encode(rndbytes);
setJwtId(jti);
}
示例7: testExamplesFromDraftEvenWithoutDirectSupportForTheHeader
import org.jose4j.base64url.Base64Url; //导入方法依赖的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()));
}
示例8: base64UrlEncode
import org.jose4j.base64url.Base64Url; //导入方法依赖的package包/类
/**
* Base64 encodes the given byte array, using URL style encoding.
*
* @param data
* byte array to base64 encode
* @return base64 encoded string
*/
public static String base64UrlEncode(byte[] data) {
return Base64Url.encode(data);
}