List of usage examples for com.google.common.io BaseEncoding base64Url
public static BaseEncoding base64Url()
From source file:com.google.devtools.build.lib.remote.blobstore.http.AbstractHttpHandler.java
protected void addCredentialHeaders(HttpRequest request, URI uri) throws IOException { String userInfo = uri.getUserInfo(); if (userInfo != null) { String value = BaseEncoding.base64Url().encode(userInfo.getBytes(Charsets.UTF_8)); request.headers().set(HttpHeaderNames.AUTHORIZATION, "Basic " + value); return;/*from www.j a v a 2 s.c o m*/ } if (credentials == null || !credentials.hasRequestMetadata()) { return; } Map<String, List<String>> authHeaders = credentials.getRequestMetadata(uri); if (authHeaders == null || authHeaders.isEmpty()) { return; } for (Map.Entry<String, List<String>> entry : authHeaders.entrySet()) { String name = entry.getKey(); for (String value : entry.getValue()) { request.headers().add(name, value); } } }
From source file:controllers.CasinoControllerHelper.java
public String createWebSafeUuid() { try {//from w w w. j a v a 2s. co m UUID uuid = UUID.randomUUID(); byte[] uuidAsBytes = uuid.toString().getBytes("UTF-8"); return BaseEncoding.base64Url().encode(uuidAsBytes); } catch (UnsupportedEncodingException unsupportedEncodingException) { String MESSAGE = "There is something really wrong. We cannot use UTF-8 encoding. Stopping."; logger.error(MESSAGE, unsupportedEncodingException); throw new RuntimeException(MESSAGE, unsupportedEncodingException); } }
From source file:org.opendedup.sdfs.filestore.cloud.utils.EncyptUtils.java
public static String encLong(long id, boolean enc) throws IOException { if (enc) {//from w w w. j ava 2 s . c o m byte[] encH = EncryptUtils.encryptCBC(Long.toString(id).getBytes()); return BaseEncoding.base64Url().encode(encH); } else { return Long.toString(id); } }
From source file:io.datawire.keystoreknife.command.ShowCommand.java
@Override public void run(Initializer<?> initializer, Namespace namespace) throws Exception { KeyStoreKnife keystore = KeyStoreKnife.create(namespace.get("keystore"), namespace.getString("keystore_type"), namespace.getString("keystore_password")); Key key = keystore.getKey(namespace.getString("alias"), namespace.getString("password")); StringBuilder result = new StringBuilder(); result.append("Key: ").append(namespace.getString("alias")).append(System.lineSeparator()) .append(System.lineSeparator()); result.append("Hex -> ").append(BaseEncoding.base16().encode(key.getEncoded()).toLowerCase()) .append(System.lineSeparator()); result.append("Base64 -> ").append(BaseEncoding.base64().encode(key.getEncoded())) .append(System.lineSeparator()); result.append("Base64 URL -> ").append(BaseEncoding.base64Url().encode(key.getEncoded())) .append(System.lineSeparator()); System.out.println(result.toString()); }
From source file:org.opendedup.sdfs.filestore.cloud.utils.EncyptUtils.java
public static long decLong(String fname, boolean enc) throws IOException { if (enc) {// ww w . j a v a 2 s .com byte[] encH = BaseEncoding.base64Url().decode(fname); String st = new String(EncryptUtils.decryptCBC(encH)); return Long.parseLong(st); } else { return Long.parseLong(fname); } }
From source file:com.eucalyptus.tokens.oidc.JsonWebSignatureVerifier.java
private static Pair<JoseHeader, byte[]> decode(@Nonnull final String jsonHeaderB64, @Nonnull final String jsonBodyB64, @Nonnull final String signatureB64) throws GeneralSecurityException, OidcParseException { final String jsonHeader; final byte[] signature; try {//from w ww . j a va 2 s . c om final BaseEncoding b64Url = BaseEncoding.base64Url(); // allow padding? jsonHeader = new String(b64Url.decode(jsonHeaderB64), StandardCharsets.UTF_8); b64Url.decode(jsonBodyB64); // ensures valid b64url encoding signature = b64Url.decode(signatureB64); } catch (final IllegalArgumentException e) { throw new GeneralSecurityException("Unable to decode", e); } final JoseHeader header = JoseHeader.parse(jsonHeader); if (header.getCrit().map(List::size).getOrElse(0) > 0) { throw new GeneralSecurityException("Unsupported critical extension " + header.getCrit()); } return Pair.pair(header, signature); }
From source file:org.apache.isis.core.runtime.services.viewmodelsupport.ViewModelSupportDefault.java
@Override public Memento parse(String str) { final byte[] bytes = BaseEncoding.base64Url().decode(str); String xmlStr = new String(bytes, Charset.forName("UTF-8")); final Document doc = Dom4jUtil.parse(xmlStr); return new MementoDefault(doc); }
From source file:io.datawire.keystoreknife.KeyStoreKnife.java
public void replaceSecret(SecretKey currentKey, String alias, String password, String newSecret, String encoding) {// ww w. j a va2 s .c o m 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:org.opendedup.sdfs.filestore.cloud.utils.EncyptUtils.java
public static String encInt(int id, boolean enc) throws IOException { if (enc) {//from ww w. j av a2s . c o m byte[] encH = EncryptUtils.encryptCBC(Integer.toString(id).getBytes()); return BaseEncoding.base64Url().encode(encH); } else { return Integer.toString(id); } }
From source file:org.opendedup.sdfs.filestore.cloud.utils.EncyptUtils.java
public static int decInt(String fname, boolean enc) throws IOException { if (enc) {//from www . j a va 2s. c om byte[] encH = BaseEncoding.base64Url().decode(fname); String st = new String(EncryptUtils.decryptCBC(encH)); return Integer.parseInt(st); } else { return Integer.parseInt(fname); } }