List of usage examples for com.google.common.io BaseEncoding base64Url
public static BaseEncoding base64Url()
From source file:com.google.dosidos.util.EncryptionUtil.java
public static String decrypt(String encryptedText, String key) { try {/*from w w w .j a v a 2s . c om*/ byte[] encrypted = BaseEncoding.base64Url().decode(encryptedText); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, getAesKey(key)); byte[] plain = cipher.doFinal(encrypted); if (plain == null || plain.length <= 8) { throw new RuntimeException("wrong encrypted text."); } byte[] data = new byte[plain.length - 8]; System.arraycopy(plain, 8, data, 0, data.length); return new String(data, "ISO-8859-1"); } 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); } }
From source file:com.wadpam.guja.oauth2.provider.DefaultTokenGenerator.java
@Override public String generate() { byte[] randomBytes = new byte[24]; random.nextBytes(randomBytes);/*from w ww . j a v a2 s . c om*/ HashCode hashCode = Hashing.goodFastHash(256).newHasher().putBytes(randomBytes).putLong(System.nanoTime()) .hash(); return BaseEncoding.base64Url().omitPadding().encode(hashCode.asBytes()); }
From source file:unportant.gist.jep180.RandomStrings.java
private String randomString(int size, Random rand) { final byte[] buffer = new byte[size]; rand.nextBytes(buffer);/*w w w.j a va 2s.c o m*/ return BaseEncoding.base64Url().omitPadding().encode(buffer); }
From source file:org.dcache.restful.events.streams.inotify.WatchIdentity.java
public WatchIdentity(String channelId, PnfsId pnfsid) { this.pnfsid = pnfsid; this.channelId = channelId; // FIXME the code ties the watch identity to the PnfsId. This should be the inumber. // REVISIT here we assume that PNFS-ID has an upper-case hexadecimal value byte[] rawValue = BaseEncoding.base16().decode(pnfsid.toString()); this.selectionId = BaseEncoding.base64Url().omitPadding().encode(rawValue); }
From source file:org.apache.isis.applib.services.urlencoding.UrlEncodingServiceUsingBaseEncoding.java
public UrlEncodingServiceUsingBaseEncoding() { this(BaseEncoding.base64Url(), Charset.forName("UTF-8")); }
From source file:org.opendedup.sdfs.filestore.cloud.utils.EncyptUtils.java
public static String encHashArchiveName(long id, boolean enc) throws IOException { if (baseEncode) return Long.toString(id); if (enc) {/* w ww. j av a2 s.co m*/ byte[] encH = EncryptUtils.encryptCBC(Long.toString(id).getBytes()); return BaseEncoding.base64Url().encode(encH); } else { return BaseEncoding.base64Url().encode(Long.toString(id).getBytes()); } }
From source file:com.google.gcloud.datastore.Cursor.java
/** * Create a {@code Cursor} given its URL safe encoded form. */// w w w. j a v a 2 s . co m public static Cursor fromUrlSafe(String urlSafe) { try { return Cursor.copyFrom(BaseEncoding.base64Url().decode(urlSafe)); } catch (IllegalArgumentException e) { throw new IllegalStateException("Unexpected decoding exception", e); } }
From source file:com.microsoft.rest.Base64Url.java
/** * Decode the bytes and return.//www .ja v a 2 s . c o m * * @return The decoded byte array. */ public byte[] getDecodedBytes() { if (this.bytes == null) { return null; } return BaseEncoding.base64Url().decode(new String(bytes)); }
From source file:com.google.firebase.auth.hash.Scrypt.java
private Scrypt(Builder builder) { super("SCRYPT", 0, 8, builder); checkArgument(builder.key != null && builder.key.length > 0, "A non-empty key is required for Scrypt"); checkArgument(builder.memoryCost > 0 && builder.memoryCost <= 14, "memoryCost must be between 1 and 14"); this.key = BaseEncoding.base64Url().encode(builder.key); if (builder.saltSeparator != null) { this.saltSeparator = BaseEncoding.base64Url().encode(builder.saltSeparator); } else {//from w ww .j a va2 s . com this.saltSeparator = BaseEncoding.base64Url().encode(new byte[0]); } this.memoryCost = builder.memoryCost; }
From source file:com.jivesoftware.os.amza.api.ring.RingMember.java
public String toBase64() { return BaseEncoding.base64Url().encode(toBytes()); }