List of usage examples for com.google.common.io BaseEncoding base64Url
public static BaseEncoding base64Url()
From source file:org.mitre.openid.connect.service.impl.MITREidDataService_1_X.java
protected static String base64UrlEncodeObject(Serializable obj) { if (obj == null) { return null; } else {//from w w w . j ava 2s.c o m String encoded = null; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(obj); encoded = BaseEncoding.base64Url().encode(baos.toByteArray()); oos.close(); baos.close(); } catch (IOException ex) { logger.error("Unable to encode object", ex); } return encoded; } }
From source file:com.lakeside.core.utils.EncodeUtils.java
/** * Base64?, URL(Base64URL?+,/=, ?RFC3548). *///from w ww .ja v a 2 s . c o m public static String base64UrlSafeEncode(byte[] input) { return BaseEncoding.base64Url().encode(input); }
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. j av a 2s . c o 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:org.spf4j.concurrent.UIDGenerator.java
public UIDGenerator(final Sequence sequence, final String prefix) { this(sequence, BaseEncoding.base64Url(), 0, '.', prefix); }
From source file:com.skubit.bitid.keystore.BitKeystoreExporter.java
public void store(OutputStream os, String password) throws Exception { final Cursor c = mContext.getContentResolver().query(KeyColumns.CONTENT_URI, null, null, null, null); KeyCursor kc = new KeyCursor(c); kc.moveToFirst();/* w ww . ja v a2s. c o m*/ KeyCrypterScrypt crypterScrypt = new KeyCrypterScrypt(512); KeyParameter aesKey = crypterScrypt.deriveKey(password); Protos.ScryptParameters params = crypterScrypt.getScryptParameters(); ScryptHeader scryptHeader = new ScryptHeader(); scryptHeader.setN(params.getN()); scryptHeader.setR(params.getR()); scryptHeader.setP(params.getP()); scryptHeader.setSalt(BaseEncoding.base64Url().encode(params.getSalt().toByteArray())); KeyStore keyStore = new KeyStore(); keyStore.setScrypt(scryptHeader); for (int i = 0; i < kc.getCount(); i++) { kc.moveToPosition(i); EncryptedData data = crypterScrypt.encrypt(kc.getPriv(), aesKey); String ecKey64 = BaseEncoding.base64Url().encode(data.encryptedBytes); KeyEntry entry = new KeyEntry(); entry.setAlias(kc.getNickname()); entry.setKty("EC"); entry.setCrv("P-256"); entry.setPk(ecKey64); entry.setIv(BaseEncoding.base64Url().encode(data.initialisationVector)); keyStore.addKey(entry); } ObjectMapper mapper = new ObjectMapper(); mapper.writeValue(os, keyStore); os.close(); }
From source file:org.opendedup.sdfs.filestore.cloud.utils.EncyptUtils.java
public static long decHashArchiveName(String fname, boolean enc) throws IOException { if (baseEncode) return Long.parseLong(new String(fname)); if (enc) {/*from www.j a v a2 s .co m*/ byte[] encH; encH = BaseEncoding.base64Url().decode(fname); String st = new String(EncryptUtils.decryptCBC(encH)); return Long.parseLong(st); } else { byte[] encH; encH = BaseEncoding.base64Url().decode(fname); return Long.parseLong(new String(encH)); } }
From source file:org.spf4j.concurrent.UIDGenerator.java
public UIDGenerator(final Sequence sequence, final long customEpoch) { this(sequence, BaseEncoding.base64Url(), customEpoch, '.', ""); }
From source file:org.fabrician.enabler.util.DockerfileBuildLock.java
private DockerfileBuildLock(String dockerImageName, File dockerFilePath) throws Exception { this.dockerImageName = dockerImageName; this.dockerFilePath = dockerFilePath; byte[] docker_bytes = FileUtils.readFileToByteArray(dockerFilePath); // we create a hash file name from the image and dockerfile content to build with... HashFunction hf = Hashing.md5();//from w ww . ja v a2 s . c o m HashCode hc = hf.newHasher().putString(dockerImageName, Charsets.UTF_8).putBytes(docker_bytes).hash(); String dockerFileHash = BaseEncoding.base64Url().encode(hc.asBytes()); File tmpDir = new File(System.getProperty("java.io.tmpdir")); lock_file = new File(tmpDir, dockerFileHash + ".dockerfile_lck"); logger.info("Attempt to acquire Dockerfile build lock at path :" + lock_file); lock_channel = FileUtils.openOutputStream(lock_file).getChannel(); lock = lock_channel.tryLock(); if (lock == null) { throw new Exception("Can't create exclusive build lock for image [" + dockerImageName + "] for Dockerfile [" + dockerFilePath + "]"); } else { logger.info("Acquired Dockerfile build lock at lock path : [" + lock_file + "]"); } }
From source file:com.google.gcloud.datastore.Cursor.java
/** * Returns the cursor in an encoded form that can be used as part of a URL. */ public String toUrlSafe() { return BaseEncoding.base64Url().encode(byteString.toByteArray()); }
From source file:com.sector91.wit.responders.Page.java
private static String hash(byte[] data) { try {//from ww w .j a va 2 s . com // By default, the ETag hash is the SHA-256 of the page content. final MessageDigest digest = MessageDigest.getInstance(HASH_FUNCTION); digest.update(data); return BaseEncoding.base64Url().encode(digest.digest()); } catch (NoSuchAlgorithmException ex) { // Fall back to using Java's hashCode of the string, prefixed with the length. return String.valueOf(data.length) + "-" + Integer.toString(new String(data, Charsets.UTF_8).hashCode(), BASE); } }