List of usage examples for com.google.common.io BaseEncoding base32Hex
public static BaseEncoding base32Hex()
From source file:com.cinchapi.concourse.server.http.HttpRequests.java
/** * Decode an auth token.//from w ww . j a v a2s .c o m * * @param token * @param request * @return an array with three elements: the first contains the actual * {@link AccessToken} and the second contains the environment that * the token was encoded with and the third contains the fingerprint * @throws GeneralSecurityException */ public static HttpAuthToken decodeAuthToken(String token) throws GeneralSecurityException { ByteBuffer cryptPack = ByteBuffer.wrap(BaseEncoding.base64Url().decode(token)); String pack = ByteBuffers.getString(ClientSecurity.decrypt(cryptPack)); String[] toks = pack.split("\\|"); return new HttpAuthToken(new AccessToken(ByteBuffer.wrap(BaseEncoding.base32Hex().decode(toks[0]))), toks[1], toks[2]); }
From source file:com.lithium.flow.util.BaseEncodings.java
@Nonnull private static BaseEncoding getEncoding(@Nonnull String name) { switch (name) { case "base16": return BaseEncoding.base16(); case "base32": return BaseEncoding.base32(); case "base32Hex": return BaseEncoding.base32Hex(); case "base64": return BaseEncoding.base64(); case "base64Url": return BaseEncoding.base64Url(); default:/*from ww w . j a v a 2 s .c o m*/ throw new RuntimeException("unknown encoding: " + name); } }
From source file:com.cinchapi.concourse.server.http.HttpRequests.java
/** * Encode an auth token. The encoded token embeds information about the * {@code environment} so that we can perform sanity checks that ensure the * environment specified in the URL is one that the auth token was actually * designed to access.//from w w w . ja v a 2 s .co m * * @param token * @param environment * @param request * @return the encoded auth token */ public static String encodeAuthToken(AccessToken token, String environment, HttpRequest request) { String base32Token = BaseEncoding.base32Hex().encode(token.getData()); String fingerprint = getFingerprint(request); String pack = base32Token + "|" + environment + "|" + fingerprint; ByteBuffer cryptPack = ClientSecurity.encrypt(pack); String base64CryptPack = BaseEncoding.base64Url().encode(ByteBuffers.toByteArray(cryptPack)); return base64CryptPack; }
From source file:io.datawire.keystoreknife.KeyStoreKnife.java
public void replaceSecret(SecretKey currentKey, String alias, String password, String newSecret, String encoding) {/*from ww w.jav a2 s. c om*/ byte[] newSecretBytes = new byte[0]; switch (encoding.toLowerCase()) { case "base16": newSecretBytes = BaseEncoding.base16().decode(newSecret); break; case "base32": newSecretBytes = BaseEncoding.base32().decode(newSecret); break; case "base32_hex": newSecretBytes = BaseEncoding.base32Hex().decode(newSecret); break; case "base64": newSecretBytes = BaseEncoding.base64().decode(newSecret); break; case "base64_url": newSecretBytes = BaseEncoding.base64Url().decode(newSecret); break; case "plain": default: newSecretBytes = newSecret.getBytes(StandardCharsets.UTF_8); break; } SecretKey newKey = new SecretKeySpec(newSecretBytes, currentKey.getAlgorithm()); KeyStore.SecretKeyEntry newKeyEntry = new KeyStore.SecretKeyEntry(newKey); setSecretKey(alias, newKeyEntry, password); }
From source file:com.github.jcustenborder.kafka.connect.utils.AssertStruct.java
public static void assertStruct(final Struct expected, final Struct actual, String message) { String prefix = Strings.isNullOrEmpty(message) ? "" : message + ": "; if (null == expected) { assertNull(actual, prefix + "actual should be null."); return;/* ww w.j a v a 2 s . co m*/ } assertSchema(expected.schema(), actual.schema(), "schema does not match."); for (Field expectedField : expected.schema().fields()) { log.trace("assertStruct() - testing field '{}'", expectedField.name()); final Object expectedValue = expected.get(expectedField.name()); final Object actualValue = actual.get(expectedField.name()); if (Decimal.LOGICAL_NAME.equals(expectedField.schema().name())) { final BigDecimal expectedDecimal = castAndVerify(BigDecimal.class, expected, expectedField, true); final BigDecimal actualDecimal = castAndVerify(BigDecimal.class, actual, expectedField, false); assertEquals(expectedDecimal, actualDecimal, prefix + expectedField.name() + " does not match."); } else if (Timestamp.LOGICAL_NAME.equals(expectedField.schema().name()) || Date.LOGICAL_NAME.equals(expectedField.schema().name()) || Time.LOGICAL_NAME.equals(expectedField.schema().name())) { final java.util.Date expectedDate = castAndVerify(java.util.Date.class, expected, expectedField, true); final java.util.Date actualDate = castAndVerify(java.util.Date.class, actual, expectedField, false); assertEquals(expectedDate, actualDate, prefix + expectedField.name() + " does not match."); } else { switch (expectedField.schema().type()) { case ARRAY: final List<Object> expectedArray = castAndVerify(List.class, expected, expectedField, true); final List<Object> actualArray = castAndVerify(List.class, actual, expectedField, false); assertEquals(expectedArray, actualArray, prefix + expectedField.name() + " does not match."); break; case MAP: final Map<Object, Object> expectedMap = castAndVerify(Map.class, expected, expectedField, true); final Map<Object, Object> actualMap = castAndVerify(Map.class, actual, expectedField, false); assertEquals(expectedMap, actualMap, prefix + expectedField.name() + " does not match."); break; case STRUCT: final Struct expectedStruct = castAndVerify(Struct.class, expected, expectedField, true); final Struct actualStruct = castAndVerify(Struct.class, actual, expectedField, false); assertStruct(expectedStruct, actualStruct, prefix + expectedField.name() + " does not match."); break; case BYTES: final byte[] expectedByteArray = castAndVerify(byte[].class, expected, expectedField, true); final byte[] actualByteArray = castAndVerify(byte[].class, actual, expectedField, false); assertEquals( null == expectedByteArray ? "" : BaseEncoding.base32Hex().encode(expectedByteArray).toString(), null == actualByteArray ? "" : BaseEncoding.base32Hex().encode(actualByteArray).toString(), prefix + expectedField.name() + " does not match."); break; default: assertEquals(expectedValue, actualValue, prefix + expectedField.name() + " does not match."); break; } } } }
From source file:org.apache.jackrabbit.oak.spi.blob.AbstractBlobStore.java
@Override public String getReference(@Nonnull String blobId) { checkNotNull(blobId, "BlobId must be specified"); try {/*from w w w . j av a 2s. c o m*/ Mac mac = Mac.getInstance(ALGORITHM); mac.init(new SecretKeySpec(getReferenceKey(), ALGORITHM)); byte[] hash = mac.doFinal(blobId.getBytes("UTF-8")); return blobId + ':' + BaseEncoding.base32Hex().encode(hash); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException(e); } catch (InvalidKeyException e) { throw new IllegalStateException(e); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } }
From source file:google.registry.bigquery.BigqueryConnection.java
/** Returns a random table name consisting only of the chars {@code [a-v0-9_]}. */ private String getRandomTableName() { byte[] randBytes = new byte[8]; // 64 bits of randomness ought to be plenty. random.nextBytes(randBytes);/*from ww w. j a v a 2 s . co m*/ return "_" + BaseEncoding.base32Hex().lowerCase().omitPadding().encode(randBytes); }