List of usage examples for com.google.common.io BaseEncoding base64Url
public static BaseEncoding base64Url()
From source file:hyweb.jo.data.JOEncoder.java
public static String encoder(byte[] buf) throws Exception { byte[] ret = LZFEncoder.encode(buf); return BaseEncoding.base64Url().encode(ret); }
From source file:hyweb.jo.data.JODecoder.java
public static String decoder(String text) throws Exception { return decoder(BaseEncoding.base64Url().decode(text)); }
From source file:com.microsoft.rest.Base64Url.java
/** * Encode a byte array into Base64Url encoded bytes. * * @param bytes The byte array to encode. * @return a Base64Url instance//from www . j av a2s . c o m */ public static Base64Url encode(byte[] bytes) { if (bytes == null) { return new Base64Url(null); } else { return new Base64Url(BaseEncoding.base64Url().omitPadding().encode(bytes)); } }
From source file:com.pinterest.deployservice.common.CommonUtils.java
/** * TODO figure out how to use guava to achive this * * @return base64 encoded shorten UUID, e.g. 11YozyYYTvKmuUXpRDvoJA *//* w ww. j a v a 2 s . c om*/ public static String getBase64UUID() { UUID uuid = UUID.randomUUID(); ByteBuffer buffer = ByteBuffer.wrap(new byte[16]); buffer.putLong(uuid.getMostSignificantBits()); buffer.putLong(uuid.getLeastSignificantBits()); String base64 = BaseEncoding.base64Url().omitPadding().encode(buffer.array()); if (base64.charAt(0) == '_') { return 'x' + base64.substring(1); } if (base64.charAt(0) == '-') { return 'X' + base64.substring(1); } return base64; }
From source file:me.j360.dubbo.modules.util.text.EncodeUtil.java
/** * Base64?, URL.(Base64URL?'+''/''-''_', ?RFC3548). *//* w w w .j a v a 2 s. c om*/ public static String encodeBase64UrlSafe(byte[] input) { return BaseEncoding.base64Url().encode(input); }
From source file:net.thangbui.cql_exporter.Utils.java
public static String randomChar() { final byte[] buffer = new byte[5]; random.nextBytes(buffer);//from ww w .ja v a2 s. c o m return BaseEncoding.base64Url().omitPadding().encode(buffer); // or base32() }
From source file:org.opendedup.sdfs.filestore.cloud.utils.EncyptUtils.java
public static String encString(String hashes, boolean enc) throws IOException { if (baseEncode) return hashes; if (enc) {/*from w ww .jav a2s .co m*/ byte[] encH = EncryptUtils.encryptCBC(hashes.getBytes()); if (baseEncode) return BaseEncoding.base64().encode(encH); else return BaseEncoding.base64Url().encode(encH); } else { return BaseEncoding.base64Url().encode(hashes.getBytes()); } }
From source file:io.macgyver.core.auth.ApiToken.java
public static ApiToken parse(String armored) { try {//from w w w . j a v a2s . c om ApiToken t = new ApiToken(); t.data = (ObjectNode) mapper.readTree(new String(BaseEncoding.base64Url().decode(armored), "UTF8")); return t; } catch (IOException | RuntimeException e) { // the exception tends to leak information about the token, so don't include it throw new MacGyverException("could not parse token"); } }
From source file:com.cinchapi.concourse.server.http.HttpRequests.java
/** * Decode an auth token./* w w w.j av a 2 s . 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.google.util.EncryptionUtil.java
public static String encrypt(String plainText) { try {/* ww w. j av a 2s. co m*/ Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, getAesKey()); byte[] salt = new byte[8]; SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); random.nextBytes(salt); cipher.update(salt); byte[] encrypted = cipher.doFinal(plainText.getBytes("ISO-8859-1")); return BaseEncoding.base64Url().encode(encrypted); } catch (InvalidKeyException e) { throw new RuntimeException(e); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } catch (NoSuchPaddingException e) { throw new RuntimeException(e); } catch (IllegalBlockSizeException e) { throw new RuntimeException(e); } catch (BadPaddingException e) { throw new RuntimeException(e); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }