List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64URLSafeString
public static String encodeBase64URLSafeString(final byte[] binaryData)
From source file:com.amazon.alexa.avs.auth.companionapp.CodeChallengeWorkflow.java
/** * This method is borrowed from the SPOP protocol spec version 10 here : http://datatracker.ietf.org/doc/draft-ietf-oauth-spop/?include_text=1 * @param arg the string to convert// www. ja v a 2 s .c o m * @return base64 URL encoded string value as specified by spec. */ private String base64UrlEncode(byte[] arg) { return Base64.encodeBase64URLSafeString(arg); }
From source file:net.sf.texprinter.utils.ExecutionLogging.java
/** * Dumps the execution plan./*from w ww .j ava2 s. c o m*/ * * @return A Base64 URL safe string. */ public String dump() { // encode the execution plan as a URL safe string and return it return Base64.encodeBase64URLSafeString(executionPlan.toString().getBytes()); }
From source file:eu.openanalytics.rsb.component.DataDirectoriesResourceTestCase.java
@Test(expected = AccessDeniedException.class) public void browsePathCraftyExtension() throws Exception { when(configuration.getDataDirectories()).thenReturn(Arrays.asList(FileUtils.getTempDirectory())); dataDirectoriesResource.setupRootMap(); dataDirectoriesResource.browsePath(dataDirectoriesResource.getRootMap().keySet().iterator().next(), Base64.encodeBase64URLSafeString("../opt".getBytes()), httpHeaders, uriInfo); }
From source file:com.turo.pushy.apns.AuthenticationToken.java
public AuthenticationToken(final ApnsSigningKey signingKey, final Date issuedAt) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException { this.header = new AuthenticationTokenHeader(signingKey.getKeyId()); this.claims = new AuthenticationTokenClaims(signingKey.getTeamId(), issuedAt); final String headerJson = GSON.toJson(this.header); final String claimsJson = GSON.toJson(this.claims); final StringBuilder payloadBuilder = new StringBuilder(); payloadBuilder.append(Base64.encodeBase64URLSafeString(headerJson.getBytes(StandardCharsets.US_ASCII))); payloadBuilder.append('.'); payloadBuilder.append(Base64.encodeBase64URLSafeString(claimsJson.getBytes(StandardCharsets.US_ASCII))); {// w ww .j av a 2s . co m final Signature signature = Signature.getInstance(ApnsKey.APNS_SIGNATURE_ALGORITHM); signature.initSign(signingKey); signature.update(payloadBuilder.toString().getBytes(StandardCharsets.US_ASCII)); this.signatureBytes = signature.sign(); } payloadBuilder.append('.'); payloadBuilder.append(Base64.encodeBase64URLSafeString(this.signatureBytes)); this.base64EncodedToken = payloadBuilder.toString(); }
From source file:com.mirth.connect.model.Event.java
public String toExportString() { StringBuilder builder = new StringBuilder(); builder.append(id + ", "); builder.append(new SimpleDateFormat(Exportable.DATE_TIME_FORMAT).format(dateTime.getTime()) + ", "); builder.append(level + ", "); builder.append(outcome + ", "); builder.append(name + ", "); builder.append(userId + ", "); builder.append(ipAddress + ", "); /*/*from ww w .j a v a2s. co m*/ * Print out the attributes and Base64 encode them in case there are * newlines. */ ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); MapUtils.verbosePrint(ps, "attributes", attributes); builder.append(Base64.encodeBase64URLSafeString(baos.toByteArray())); builder.append(System.getProperty("line.separator")); IOUtils.closeQuietly(ps); return builder.toString(); }
From source file:gt.dakaik.common.Common.java
public static Message createMessageWithEmail(MimeMessage email) throws MessagingException, IOException { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); email.writeTo(bytes);/* w w w .j a v a 2 s. com*/ String encodedEmail = Base64.encodeBase64URLSafeString(bytes.toByteArray()); Message message = new Message(); message.setRaw(encodedEmail); return message; }
From source file:com.pfarrell.crypto.HmacUtil.java
/** * gets a string nonce of the length specified in len, encoded in Base64 "safe mode"/ * The url-safe variation emits - and _ instead of + and / characters. * @param len length of output desired.//from w ww . j a v a 2 s. c o m * @return a string nonce */ public static final String getNonce(int len) { byte[] buf = new byte[len]; SecRandom rg = SecRandom.getInstance(); rg.nextBytes(buf); StringBuilder rval = new StringBuilder(); String encoded = Base64.encodeBase64URLSafeString(buf); rval.append(encoded); rval.setLength(len); return rval.toString(); }
From source file:com.wavemaker.runtime.ws.SyndFeedService.java
/** * Reads from the InputStream of the specified URL and builds the feed object from the returned XML. * /*w ww .ja va 2 s . c o m*/ * @param feedURL The URL to read feed from. * @param httpBasicAuthUsername The username for HTTP Basic Authentication. * @param httpBasicAuthPassword The password for HTTP Basic Authentication. * @param connectionTimeout HTTP connection timeout. * @return A feed object. */ @ExposeToClient public Feed getFeedWithHttpConfig(String feedURL, String httpBasicAuthUsername, String httpBasicAuthPassword, int connectionTimeout) { URL url = null; try { url = new URL(feedURL); } catch (MalformedURLException e) { throw new WebServiceInvocationException(e); } SyndFeedInput input = new SyndFeedInput(); try { URLConnection urlConn = url.openConnection(); if (urlConn instanceof HttpURLConnection) { urlConn.setAllowUserInteraction(false); urlConn.setDoInput(true); urlConn.setDoOutput(false); ((HttpURLConnection) urlConn).setInstanceFollowRedirects(true); urlConn.setUseCaches(false); urlConn.setRequestProperty(USER_AGENT_KEY, USER_AGENT_VALUE); urlConn.setConnectTimeout(connectionTimeout); if (httpBasicAuthUsername != null && httpBasicAuthUsername.length() > 0) { String auth = httpBasicAuthPassword == null ? httpBasicAuthUsername : httpBasicAuthUsername + ":" + httpBasicAuthPassword; urlConn.setRequestProperty(BASIC_AUTH_KEY, BASIC_AUTH_VALUE_PREFIX + Base64.encodeBase64URLSafeString(auth.getBytes())); } } SyndFeed feed = input.build(new XmlReader(urlConn)); return FeedBuilder.getFeed(feed); } catch (IllegalArgumentException e) { throw new WebServiceInvocationException(e); } catch (FeedException e) { throw new WebServiceInvocationException(e); } catch (IOException e) { throw new WebServiceInvocationException(e); } }
From source file:com.monitor.baseservice.utils.XCodeUtil.java
public static String xEncode(Map<String, Object> params) { String info = JSONObject.toJSONString(params); byte[] data = info.getBytes(); xorCode(data, XOR_KEY);/*w w w .j a va 2s .c o m*/ byte[] crc = crcUnsigned(data, CRC_KEY.getBytes()); byte[] tmp = new byte[data.length + crc.length]; for (int i = 0; i < data.length; i++) { tmp[i] = data[i]; } for (int i = 0; i < crc.length; i++) { tmp[i + data.length] = crc[i]; } data = tmp; String xcode = createPrefix(PREFIX_LENGTH) + Base64.encodeBase64URLSafeString(data); return xcode; }
From source file:com.servoy.j2db.util.SecuritySupport.java
@SuppressWarnings("nls") public static String encryptUrlSafe(Settings settings, String value) throws Exception { if (value == null) return value; Cipher cipher = Cipher.getInstance("DESede"); cipher.init(Cipher.ENCRYPT_MODE, SecuritySupport.getCryptKey(settings)); return Base64.encodeBase64URLSafeString(cipher.doFinal(value.getBytes())); }