List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64URLSafeString
public static String encodeBase64URLSafeString(final byte[] binaryData)
From source file:edu.tamu.tcat.crypto.spongycastle.SecureTokenImpl.java
@Override public String getToken(ByteBuffer content) throws TokenException { try {/*from www . ja v a 2s .com*/ byte[] token = createToken(content.slice()); byte[] iv = createIV(); Cipher cipher = createCipher(Cipher.ENCRYPT_MODE, iv); int outputSize = cipher.getOutputSize(token.length); byte[] encrypted = new byte[outputSize + (ivSize / 8)]; System.arraycopy(iv, 0, encrypted, 0, iv.length); cipher.doFinal(token, 0, token.length, encrypted, iv.length); String encoded = Base64.encodeBase64URLSafeString(encrypted); return encoded; } catch (NoSuchAlgorithmException e) { throw new TokenException("Missing algorithm", e); } catch (IllegalBlockSizeException e) { throw new TokenException( "Should never happen but is thrown because Sun/Oracle doesn't understand that encryption/decryption modes are different and should really have different APIs. This is a decrypt only problem", e); } catch (BadPaddingException e) { throw new TokenException( "Should never happen but is thrown because Sun/Oracle doesn't understand that encryption/decryption modes are different and should really have different APIs. This is a decrypt only problem", e); } catch (ShortBufferException e) { throw new TokenException("Should never happen", e); } }
From source file:de.unirostock.sems.cbarchive.web.dataholder.UserData.java
@JsonIgnore public String toJson() throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString((UserData) this); json = Base64.encodeBase64URLSafeString(json.getBytes()); return json;/*w w w. j a v a 2s. c o m*/ }
From source file:com.googlecode.ehcache.annotations.key.MessageDigestCacheKeyGenerator.java
/** * Encode the digested hash bytes as a String *///from w w w. j a v a2s . c o m protected String encodeHash(final byte[] digest) { return Base64.encodeBase64URLSafeString(digest); }
From source file:com.muk.ext.security.impl.DefaultNonceService.java
private String hash(String salt, String payload) throws NoSuchAlgorithmException, InvalidKeyException { Mac sha256_HMAC = Mac.getInstance("HmacSHA256"); SecretKeySpec secret_key = new SecretKeySpec(salt.getBytes(), "HmacSHA256"); sha256_HMAC.init(secret_key);//from ww w. j a v a 2 s .c om return Base64.encodeBase64URLSafeString(sha256_HMAC.doFinal(payload.getBytes())); }
From source file:com.squid.kraken.v4.api.core.bookmark.BookmarkFolderServiceBaseImpl.java
public BookmarkFolder read(AppContext ctx, String pathBase64) { BookmarkFolder bf = new BookmarkFolder(); String fullPath = buildBookmarksPath(ctx, pathBase64); String bookmarkFolderOid = Base64.encodeBase64URLSafeString(fullPath.getBytes()); bf.setId(new BookmarkFolderPK(ctx.getCustomerId(), bookmarkFolderOid)); if (pathBase64 != null) { bf.setName(buildFolderName(ctx, fullPath)); }//from w w w. j a va 2s. com List<Bookmark> bookmarks = getBookmarks(ctx, fullPath, pathBase64 == null); // build the folder content List<BookmarkLink> bmList = new ArrayList<BookmarkLink>(); for (Bookmark o : bookmarks) { String p = o.getPath(); // only handle the exact path if (p.equals(fullPath)) { BookmarkLink bm = new BookmarkLink(o.getId()); bm.setName(o.getName()); bm.setDescription(o.getDescription()); bmList.add(bm); } } bf.setBookmarks(bmList); return bf; }
From source file:edu.tamu.tcat.crypto.bouncycastle.SecureTokenImpl.java
@Override public String getToken(ByteBuffer content) throws TokenException { try {/* w ww.j a v a 2 s . c o m*/ byte[] token = createToken(content.slice()); byte[] iv = createIV(); Cipher cipher = createCipher(Cipher.ENCRYPT_MODE, iv); int outputSize = cipher.getOutputSize(token.length); // The token value returned contains the IV followed by the encrypted payload byte[] encrypted = new byte[outputSize + (ivSize / 8)]; System.arraycopy(iv, 0, encrypted, 0, iv.length); cipher.doFinal(token, 0, token.length, encrypted, iv.length); String encoded = Base64.encodeBase64URLSafeString(encrypted); return encoded; } catch (NoSuchAlgorithmException e) { throw new TokenException("Missing algorithm", e); } catch (IllegalBlockSizeException e) { throw new TokenException( "Should never happen but is thrown because Sun/Oracle doesn't understand that encryption/decryption modes are different and should really have different APIs. This is a decrypt only problem", e); } catch (BadPaddingException e) { throw new TokenException( "Should never happen but is thrown because Sun/Oracle doesn't understand that encryption/decryption modes are different and should really have different APIs. This is a decrypt only problem", e); } catch (ShortBufferException e) { throw new TokenException("Should never happen", e); } }
From source file:com.google.u2f.server.impl.U2FServerReferenceImpl.java
@Override public RegistrationRequest getRegistrationRequest(String accountName, String appId) { Log.info(">> getRegistrationRequest " + accountName); byte[] challenge = challengeGenerator.generateChallenge(accountName); EnrollSessionData sessionData = new EnrollSessionData(accountName, appId, challenge); String sessionId = dataStore.storeSessionData(sessionData); String challengeBase64 = Base64.encodeBase64URLSafeString(challenge); Log.info("-- Output --"); Log.info(" sessionId: " + sessionId); Log.info(" challenge: " + Hex.encodeHexString(challenge)); Log.info("<< getRegistrationRequest " + accountName); return new RegistrationRequest(U2FConsts.U2F_V2, challengeBase64, appId, sessionId); }
From source file:com.monitor.baseservice.utils.XCodeUtil.java
public static String hmacSha1(String value, String key) { try {//from ww w . j av a 2s . c o m // Get an hmac_sha1 key from the raw key bytes byte[] keyBytes = key.getBytes(); SecretKeySpec signingKey = new SecretKeySpec(keyBytes, "HmacSHA1"); // Get an hmac_sha1 Mac instance and initialize with the signing key Mac mac = Mac.getInstance("HmacSHA1"); mac.init(signingKey); // Compute the hmac on input data bytes byte[] rawHmac = mac.doFinal(value.getBytes()); return Base64.encodeBase64URLSafeString(rawHmac); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } catch (InvalidKeyException e) { throw new RuntimeException(e); } }
From source file:de.nx42.maps4cim.map.texture.osm.OsmHash.java
protected static String getQueryHashLocation(Area bounds) throws IOException { /*/*from w w w . j a v a2s. com*/ * - base64 encode, every char holds 6 bits (2^6 = 64) * - 3 chars per float = 18bit precision = enough for 3 sigificant digits * for numbers <256 (which is the case in WGS84) * - 4 values -> 12 chars. 72bit or 8 byte of information * - use URL safe encoding, or file name failures are expected! */ // calculate size: 4 values, 8 bits per byte int bufSize = (int) Math.ceil(4 * locationPrecision / 8.0); ByteBuffer byteBuf = ByteBuffer.allocate(bufSize); BitOutput bitOut = BitOutput.newInstance(byteBuf); // direct storeCoordinate(bounds.getMinLat(), bitOut); storeCoordinate(bounds.getMaxLat(), bitOut); storeCoordinate(bounds.getMinLon(), bitOut); storeCoordinate(bounds.getMaxLon(), bitOut); // get array, return as Base64 (URL safe) byte[] ar = byteBuf.array(); return Base64.encodeBase64URLSafeString(ar); }
From source file:com.google.u2f.server.data.SecurityKeyData.java
@Override public String toString() { return new StringBuilder().append("public_key: ").append(Base64.encodeBase64URLSafeString(publicKey)) .append("\n").append("key_handle: ").append(Base64.encodeBase64URLSafeString(keyHandle)) .append("\n").append("counter: ").append(counter).append("\n").append("attestation certificate:\n") .append(attestationCert.toString()).append("transports: ").append(transports).append("\n") .toString();//from w w w . ja va 2 s. co m }