• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Base64类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.ning.http.util.Base64的典型用法代码示例。如果您正苦于以下问题:Java Base64类的具体用法?Java Base64怎么用?Java Base64使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Base64类属于com.ning.http.util包,在下文中一共展示了Base64类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: calculateAndAddSignature

import com.ning.http.util.Base64; //导入依赖的package包/类
@Override
public void calculateAndAddSignature(Request request, RequestBuilderBase<?> builder) {
    long now = Long.parseLong(request.getHeaders().getFirstValue("X-Buttercoin-Date"));

    StringBuilder signature = new StringBuilder();
    signature.append(now);
    signature.append(request.getUrl());
    if (request.getStringData() != null && request.getStringData().length() > 0)
        signature.append(request.getStringData());

    builder.addHeader("X-Buttercoin-Access-Key", apiKey);

    Mac mac;
    try {
        mac = (Mac) SHARED_MAC.clone();
        mac.init(signingKey);
    } catch (CloneNotSupportedException | InvalidKeyException e) {
        throw new RuntimeException(e);
    }

    builder.addHeader("X-Buttercoin-Signature", Base64.encode(mac.doFinal(Base64.encode((signature.toString()).getBytes()).getBytes())));
}
 
开发者ID:buttercoin,项目名称:buttercoin-java,代码行数:23,代码来源:HMAC256SignatureCalculator.java


示例2: testBasicAuth

import com.ning.http.util.Base64; //导入依赖的package包/类
@Test
public void testBasicAuth() throws Exception {

  dispatcher.enqueue(input -> {
    final String authHeader = input.getHeader(HttpHeaders.Names.AUTHORIZATION).replace("Basic ", "");
    final String credentials = new String(Base64.decode(authHeader));
    return new MockResponse().setBody(credentials);
  });

  final String basicUsername = "moshe";
  final String basicPassword = "junkhead";

  final HttpClient httpClient = HttpClient.createDefault();
  final String url = server.url("/basicAuth").toString();
  final Response response = httpClient.get(url).withBasicAuth(basicUsername, basicPassword).asResponse().get();

  final String basicAuthHeader = basicUsername + ":" + basicPassword;
  assertEquals("response should be '" + basicAuthHeader + "'", basicAuthHeader, response.getResponseBody());
}
 
开发者ID:outbrain,项目名称:ob1k,代码行数:20,代码来源:ClientBasicFlowsTest.java


示例3: requestToken

import com.ning.http.util.Base64; //导入依赖的package包/类
private void requestToken() {
    boolean tokenPresent = !isEmpty(connection.getToken());
    boolean usernamePresent = !isEmpty(connection.getUsername());
    boolean passwordPresent = !isEmpty(connection.getPassword());

    if (!tokenPresent && usernamePresent && passwordPresent) {
        Map<String, String> parameters = new HashMap<String, String>();
        String authString = Base64.encode((connection.getUsername() + ":" + connection.getPassword()).getBytes());
        parameters.put("Authorization", "Basic " + authString);

        User user = postDocument(SIGN_IN_URL, parameters, User.class);
        if (user != null) {
            logger.debug("Plex login successful");
            connection.setToken(user.getAuthenticationToken());
        } else {
            logger.warn("Invalid credentials for Plex account");
        }
    }
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:20,代码来源:PlexConnector.java


示例4: signData

import com.ning.http.util.Base64; //导入依赖的package包/类
/**
 *
 * @param data the string to sign
 * @return base64 encoding of the HMAC-SHA1 hash of the data parameter using {@code secretKey} as cipher key.
 */
protected String signData (String data) {
    try {
        SecretKeySpec keySpec = new SecretKeySpec(secretKey.getBytes(), HMAC_ALGORITHM);
        Mac mac = Mac.getInstance(HMAC_ALGORITHM);
        mac.init(keySpec);
        return Base64.encode(mac.doFinal(data.getBytes(CHARSET_ISO_8859_1))); // data is ASCII except HTTP header values which can be ISO_8859_1
    } catch (Exception e) {
        return null;
    }
}
 
开发者ID:ElevenPaths,项目名称:tacyt-sdk-java,代码行数:16,代码来源:BaseSdk.java


示例5: signData

import com.ning.http.util.Base64; //导入依赖的package包/类
/**
 *
 * @param data the string to sign
 * @return base64 encoding of the HMAC-SHA1 hash of the data parameter using {@code secretKey} as cipher key.
 */
private String signData (String data) {
    try {
        SecretKeySpec keySpec = new SecretKeySpec(secretKey.getBytes(), HMAC_ALGORITHM);
        Mac mac = Mac.getInstance(HMAC_ALGORITHM);
        mac.init(keySpec);
        return Base64.encode(mac.doFinal(data.getBytes(CHARSET_ISO_8859_1))); // data is ASCII except HTTP header values which can be ISO_8859_1
    } catch (Exception e) {
        return null;
    }
}
 
开发者ID:jaesga,项目名称:latch-facebook-hack,代码行数:16,代码来源:Latch.java


示例6: decode

import com.ning.http.util.Base64; //导入依赖的package包/类
private String decode(final String encodedCredentials) {
  try {
    return new String(Base64.decode(encodedCredentials), CharsetUtil.UTF_8);
  } catch (final Exception e) {
    logger.error("Error decoding credentials " + encodedCredentials, e);
    return null;
  }
}
 
开发者ID:outbrain,项目名称:ob1k,代码行数:9,代码来源:BasicAuthenticationHeaderParser.java


示例7: populateRequestWithCredentials

import com.ning.http.util.Base64; //导入依赖的package包/类
private void populateRequestWithCredentials(final String username, final String password) {
  final String authHeader = "Authorization";
  final String credentials = username + ":" + password;
  final String encodedCredentials = Base64.encode(credentials.getBytes());
  final String headerValue = "Basic " + encodedCredentials;
  when(request.getHeader(authHeader)).thenReturn(headerValue);
}
 
开发者ID:outbrain,项目名称:ob1k,代码行数:8,代码来源:HttpBasicAccessAuthenticatorTest.java


示例8: signData

import com.ning.http.util.Base64; //导入依赖的package包/类
/**
 *
 * @param data the string to sign
 * @return base64 encoding of the HMAC-SHA1 hash of the data parameter using {@code secretKey} as cipher key.
 */
private String signData (String data) {
	try {
		SecretKeySpec keySpec = new SecretKeySpec(secretKey.getBytes(), HMAC_ALGORITHM);
		Mac mac = Mac.getInstance(HMAC_ALGORITHM);
		mac.init(keySpec);
		return Base64.encode(mac.doFinal(data.getBytes()));
	} catch (Exception e) {
		return null;
	}
}
 
开发者ID:ElevenPaths,项目名称:latch-plugin-open-xchange,代码行数:16,代码来源:Latch.java



注:本文中的com.ning.http.util.Base64类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SocketClient类代码示例发布时间:2022-05-23
下一篇:
Java InBandBytestreamSession类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap