List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64URLSafeString
public static String encodeBase64URLSafeString(final byte[] binaryData)
From source file:net.foreworld.util.RestUtil.java
public static String genApiKey() { try {/* www. j ava 2s. co m*/ KeyGenerator generator = KeyGenerator.getInstance("HmacSHA1"); SecretKey key = generator.generateKey(); String encodedKey = Base64.encodeBase64URLSafeString(key.getEncoded()); return encodedKey; } catch (NoSuchAlgorithmException ignore) { } return null; }
From source file:com.opengamma.util.rest.RestUtils.java
/** * Encodes an object into base-64 suitable for a URI. * <p>/*from w ww .j ava 2s . com*/ * The conversion uses Fudge, thus the object must be convertible to/from Fudge. * * @param object the object to encode, not null * @return the encoded version of the object, not null */ public static String encodeBase64(final Object object) { FudgeContext context = OpenGammaFudgeContext.getInstance(); FudgeMsg msg = context.toFudgeMsg(object).getMessage(); byte[] byteArray = context.toByteArray(msg); return Base64.encodeBase64URLSafeString(byteArray); }
From source file:$.Encodes.java
/** * Base64?, URL(Base64URL?'+''/''-''_', ?RFC3548). *//*from w ww . jav a 2 s. co m*/ public static String encodeUrlSafeBase64(byte[] input) { return Base64.encodeBase64URLSafeString(input); }
From source file:de.kbs.acavis.service.SerializationHelper.java
public static String serializePublicationIdentifierBase64(PublicationIdentifier identifier) throws IOException { return Base64.encodeBase64URLSafeString(serializePublicationIdentifier(identifier).getBytes("UTF-8")); }
From source file:com.networknt.utility.Util.java
/** * Generate UUID across the entire app and it is used for correlationId. * * @return String correlationId/*from w ww .j av a 2 s . co m*/ */ public static String getUUID() { UUID id = UUID.randomUUID(); ByteBuffer bb = ByteBuffer.wrap(new byte[16]); bb.putLong(id.getMostSignificantBits()); bb.putLong(id.getLeastSignificantBits()); return Base64.encodeBase64URLSafeString(bb.array()); }
From source file:com.billing.ng.crypto.util.HashUtils.java
/** * Generates an alphanumeric salted hash token using the configured digest algorithm. The generated hash * is stripped of all non-alphanumeric characters to make it safe for use as an HTTP GET parameter value. * * @see com.billing.ng.crypto.context.HashAlgorithmHolder * * @param base string to use as the primary basis of the hash * @param appends additional strings to append to the plain-text password before hashing * @return hash string//w w w . j a va 2 s .co m */ public static String generateHash(String base, String... appends) { StringBuffer plainText = new StringBuffer(); plainText.append(base); for (String string : appends) plainText.append(string); HashAlgorithm algorithm = HashAlgorithmHolder.getAlgorithm(); byte[] bytes = algorithm.digestBytes(plainText.toString()); return Base64.encodeBase64URLSafeString(bytes); }
From source file:com.vmware.identity.openidconnect.common.Identifier.java
public Identifier() { byte[] randomBytes = new byte[BYTE_LENGTH]; Identifier.secureRandom.nextBytes(randomBytes); this.value = Base64.encodeBase64URLSafeString(randomBytes); }
From source file:com.nestedbird.util.UUIDConverter.java
/** * Turns a UUID in string format to a Base64 encoded version * * @param uuidString String representation of the uuid * @return base64 encoded version of the uuid * @throws IllegalArgumentException String must be a valid uuid * @throws NullPointerException String cannot be null *//*from ww w . ja v a 2 s . c o m*/ public static String toBase64(final String uuidString) { if (uuidString == null) throw new NullPointerException("String cannot be null"); if (!isUUID(uuidString)) throw new IllegalArgumentException("string must be a valid uuid"); final UUID uuid = UUID.fromString(uuidString); final ByteBuffer bb = ByteBuffer.wrap(new byte[16]); bb.putLong(uuid.getMostSignificantBits()); bb.putLong(uuid.getLeastSignificantBits()); return Base64.encodeBase64URLSafeString(bb.array()); }
From source file:com.crushpaper.UuidlIdGenerator.java
@Override public String getAnotherId() { final UUID uuid = UUID.randomUUID(); final ByteBuffer bb = ByteBuffer.wrap(new byte[16]); bb.putLong(uuid.getMostSignificantBits()); bb.putLong(uuid.getLeastSignificantBits()); return Base64.encodeBase64URLSafeString(bb.array()); }
From source file:com.squarespace.gibson.GibsonUtils.java
public static String signature(ILoggingEvent evt) { if (evt == null) { throw new NullPointerException("event"); }/*from w ww .j a va 2 s. c om*/ MessageDigest md = FACTORY.newMessageDigest(); append(md, evt.getLoggerName()); append(md, getMarker(evt)); append(md, getLevel(evt)); ThrowableProxy proxy = (ThrowableProxy) evt.getThrowableProxy(); if (proxy != null) { append(md, proxy.getThrowable()); } return Base64.encodeBase64URLSafeString(md.digest()); }