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


Java Base64类代码示例

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


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

示例1: NTLMMessage

import org.asynchttpclient.util.Base64; //导入依赖的package包/类
/** Constructor to use when message contents are known */
NTLMMessage(final String messageBody, final int expectedType) throws NtlmEngineException {
    messageContents = Base64.decode(messageBody);
    // Look for NTLM message
    if (messageContents.length < SIGNATURE.length) {
        throw new NtlmEngineException("NTLM message decoding error - packet too short");
    }
    int i = 0;
    while (i < SIGNATURE.length) {
        if (messageContents[i] != SIGNATURE[i]) {
            throw new NtlmEngineException("NTLM message expected - instead got unrecognized bytes");
        }
        i++;
    }

    // Check to be sure there's a type 2 message indicator next
    final int type = readULong(SIGNATURE.length);
    if (type != expectedType) {
        throw new NtlmEngineException("NTLM type " + Integer.toString(expectedType) + " message expected - instead got type "
                + Integer.toString(type));
    }

    currentOutputPosition = messageContents.length;
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:25,代码来源:NtlmEngine.java

示例2: testGenerateType3MsgThrowsExceptionWhenUnicodeSupportNotIndicated

import org.asynchttpclient.util.Base64; //导入依赖的package包/类
@Test(expectedExceptions = NtlmEngineException.class)
public void testGenerateType3MsgThrowsExceptionWhenUnicodeSupportNotIndicated() {
    ByteBuf buf = Unpooled.directBuffer();
    buf.writeBytes("NTLMSSP".getBytes(StandardCharsets.US_ASCII));
    buf.writeByte(0);
    // type 2 indicator
    buf.writeByte(2).writeByte(0).writeByte(0).writeByte(0);
    buf.writeLong(1);
    // flags
    buf.writeByte(0);// unicode support indicator
    buf.writeByte(0).writeByte(0).writeByte(0);
    buf.writeLong(1);// challenge
    NtlmEngine engine = new NtlmEngine();
    engine.generateType3Msg("username", "passowrd", "localhost", "workstattion", Base64.encode(ByteBufUtils.byteBuf2Bytes(buf)));
    fail("An NtlmEngineException must have occurred as unicode support is not indicated");
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:17,代码来源:NtlmTest.java

示例3: testGenerateType3Msg

import org.asynchttpclient.util.Base64; //导入依赖的package包/类
@Test
public void testGenerateType3Msg() {
    ByteBuf buf = Unpooled.directBuffer();
    buf.writeBytes("NTLMSSP".getBytes(StandardCharsets.US_ASCII));
    buf.writeByte(0);
    // type 2 indicator
    buf.writeByte(2).writeByte(0).writeByte(0).writeByte(0);
    buf.writeLong(0);
    // flags
    buf.writeByte(1);// unicode support indicator
    buf.writeByte(0).writeByte(0).writeByte(0);
    buf.writeLong(1);// challenge
    NtlmEngine engine = new NtlmEngine();
    String type3Msg = engine.generateType3Msg("username", "passowrd", "localhost", "workstattion",
            Base64.encode(ByteBufUtils.byteBuf2Bytes(buf)));
    assertEquals(type3Msg,
            "TlRMTVNTUAADAAAAGAAYAEgAAAAYABgAYAAAABIAEgB4AAAAEAAQAIoAAAAYABgAmgAAAAAAAACyAAAAAQAAAgUBKAoAAAAPmr/wN76Y0WPoSFkHghgpi0yh7/UexwVlCeoo1CQEl9d2alfPRld8KYeOkS0GdTuMTABPAEMAQQBMAEgATwBTAFQAdQBzAGUAcgBuAGEAbQBlAHcAbwByAGsAcwB0AGEAdAB0AGkAbwBuAA==",
            "Incorrect type3 message generated");
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:20,代码来源:NtlmTest.java

示例4: getResponse

import org.asynchttpclient.util.Base64; //导入依赖的package包/类
/**
 * Returns the response that has been generated after shrinking the
 * array if required and base64 encodes the response.
 *
 * @return The response as above.
 */
String getResponse() {
    final byte[] resp;
    if (messageContents.length > currentOutputPosition) {
        final byte[] tmp = new byte[currentOutputPosition];
        System.arraycopy(messageContents, 0, tmp, 0, currentOutputPosition);
        resp = tmp;
    } else {
        resp = messageContents;
    }
    return Base64.encode(resp);
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:18,代码来源:NtlmEngine.java

示例5: generateNonce

import org.asynchttpclient.util.Base64; //导入依赖的package包/类
protected String generateNonce() {
        byte[] nonceBuffer = NONCE_BUFFER.get();
        ThreadLocalRandom.current().nextBytes(nonceBuffer);
        // let's use base64 encoding over hex, slightly more compact than hex or decimals
        return Base64.encode(nonceBuffer);
//      return String.valueOf(Math.abs(random.nextLong()));
    }
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:8,代码来源:OAuthSignatureCalculator.java

示例6: testGenerateType3MsgThworsExceptionWhenType2IndicatorNotPresent

import org.asynchttpclient.util.Base64; //导入依赖的package包/类
@Test(expectedExceptions = NtlmEngineException.class)
public void testGenerateType3MsgThworsExceptionWhenType2IndicatorNotPresent() {
    ByteBuf buf = Unpooled.directBuffer();
    buf.writeBytes("NTLMSSP".getBytes(StandardCharsets.US_ASCII));
    buf.writeByte(0);
    // type 2 indicator
    buf.writeByte(3).writeByte(0).writeByte(0).writeByte(0);
    buf.writeBytes("challenge".getBytes());
    NtlmEngine engine = new NtlmEngine();
    engine.generateType3Msg("username", "passowrd", "localhost", "workstation", Base64.encode(ByteBufUtils.byteBuf2Bytes(buf)));
    fail("An NtlmEngineException must have occurred as type 2 indicator is incorrect");
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:13,代码来源:NtlmTest.java

示例7: InfluxDBClient

import org.asynchttpclient.util.Base64; //导入依赖的package包/类
/**
 * Creates a new {@link InfluxDBClient} instance.
 *
 * @param config the configuratoon.
 */
public InfluxDBClient(InfluxDBMetricsConfig config) {
    this.config = config;

    DefaultAsyncHttpClientConfig.Builder builder = new DefaultAsyncHttpClientConfig.Builder();
    this.asyncHttpClient = new DefaultAsyncHttpClient(builder.build());
    this.bbos = new ByteBufferOutputStream(ByteBuffer.allocate(BUFFER_ALLOC));

    this.credentials = Base64.encode((config.getUsername() + ":" + config.getPassword()).getBytes());

    createDatabase(this.config.getDatabase());
}
 
开发者ID:fhussonnois,项目名称:kafka-influxdb-reporter,代码行数:17,代码来源:InfluxDBClient.java

示例8: hash

import org.asynchttpclient.util.Base64; //导入依赖的package包/类
/**
 * Get the hash encoding of a key string.
 *
 * @param key  The input string to encode.
 *
 * @return The hash encoding of the key as string. Returns null if the method fails to produce a hash.
 */
public String hash(String key) {
    try {
        MessageDigest md = MessageDigest.getInstance(algorithm);
        byte[] keyBytes = key.getBytes("UTF-8");
        md.update(keyBytes, 0, keyBytes.length);
        byte[] binaryhash = md.digest();
        return Base64.encode(binaryhash);
    } catch (Exception e) {
        LOG.warn("Failed to get hash encoding for key: {}", key, e);
        return key;
    }
}
 
开发者ID:yahoo,项目名称:fili,代码行数:20,代码来源:HashDataCache.java

示例9: getKey

import org.asynchttpclient.util.Base64; //导入依赖的package包/类
public static String getKey() {
    byte[] nonce = createRandomBytes(16);
    return Base64.encode(nonce);
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:5,代码来源:WebSocketUtils.java

示例10: getAcceptKey

import org.asynchttpclient.util.Base64; //导入依赖的package包/类
public static String getAcceptKey(String key) throws UnsupportedEncodingException {
    String acceptSeed = key + MAGIC_GUID;
    byte[] sha1 = sha1(acceptSeed.getBytes(US_ASCII));
    return Base64.encode(sha1);
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:6,代码来源:WebSocketUtils.java

示例11: testGenerateType3MsgThrowsExceptionWhenChallengeTooShort

import org.asynchttpclient.util.Base64; //导入依赖的package包/类
@Test(expectedExceptions = NtlmEngineException.class)
public void testGenerateType3MsgThrowsExceptionWhenChallengeTooShort() {
    NtlmEngine engine = new NtlmEngine();
    engine.generateType3Msg("username", "passowrd", "localhost", "workstattion", Base64.encode("a".getBytes()));
    fail("An NtlmEngineException must have occurred as challenge length is too short");
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:7,代码来源:NtlmTest.java

示例12: testGenerateType3MsgThrowsExceptionWhenChallengeDoesNotFollowCorrectFormat

import org.asynchttpclient.util.Base64; //导入依赖的package包/类
@Test(expectedExceptions = NtlmEngineException.class)
public void testGenerateType3MsgThrowsExceptionWhenChallengeDoesNotFollowCorrectFormat() {
    NtlmEngine engine = new NtlmEngine();
    engine.generateType3Msg("username", "passowrd", "localhost", "workstattion", Base64.encode("challenge".getBytes()));
    fail("An NtlmEngineException must have occurred as challenge format is not correct");
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:7,代码来源:NtlmTest.java

示例13: calculateSignature

import org.asynchttpclient.util.Base64; //导入依赖的package包/类
/**
 * Method for calculating OAuth signature using HMAC/SHA-1 method.
 * 
 * @param method the request methode
 * @param uri the request Uri
 * @param oauthTimestamp the timestamp
 * @param nonce the nonce
 * @param formParams the formParams
 * @param queryParams the query params
 * @return the signature
 */
public String calculateSignature(String method, Uri uri, long oauthTimestamp, String nonce,
                                 List<Param> formParams, List<Param> queryParams) {

    StringBuilder sb = signatureBaseString(method, uri, oauthTimestamp, nonce, formParams, queryParams);

    ByteBuffer rawBase = StringUtils.charSequence2ByteBuffer(sb, UTF_8);
    byte[] rawSignature = mac.digest(rawBase);
    // and finally, base64 encoded... phew!
    return Base64.encode(rawSignature);
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:22,代码来源:OAuthSignatureCalculator.java


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