當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。