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


Java Base64Url.encode方法代码示例

本文整理汇总了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);
}
 
开发者ID:Livefyre,项目名称:livefyre-java-utils,代码行数:21,代码来源:Collection.java

示例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);
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:16,代码来源:X509Util.java

示例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));
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:31,代码来源:Pbes2HmacShaWithAesKeyWrapAlgorithmTest.java

示例4: getEncoded

import org.jose4j.base64url.Base64Url; //导入方法依赖的package包/类
private String getEncoded()
{
    return Base64Url.encode(octetSequence);
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:5,代码来源:OctetSequenceJsonWebKey.java

示例5: calculateBase64urlEncodedThumbprint

import org.jose4j.base64url.Base64Url; //导入方法依赖的package包/类
public String calculateBase64urlEncodedThumbprint(String hashAlgorithm)
{
    byte[] thumbprint = calculateThumbprint(hashAlgorithm);
    return Base64Url.encode(thumbprint);
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:6,代码来源:JsonWebKey.java

示例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);
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:7,代码来源:JwtClaims.java

示例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()));
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:56,代码来源:JwsUnencodedPayloadOptionTest.java

示例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);
}
 
开发者ID:shred,项目名称:acme4j,代码行数:11,代码来源:AcmeUtils.java


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