本文整理汇总了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;
}
示例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");
}
示例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");
}
示例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);
}
示例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()));
}
示例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");
}
示例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());
}
示例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;
}
}
示例9: getKey
import org.asynchttpclient.util.Base64; //导入依赖的package包/类
public static String getKey() {
byte[] nonce = createRandomBytes(16);
return Base64.encode(nonce);
}
示例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);
}
示例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");
}
示例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");
}
示例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);
}