List of usage examples for org.apache.commons.codec.binary Base64 decodeBase64
public static byte[] decodeBase64(final byte[] base64Data)
From source file:jp.eisbahn.oauth2.server.utils.Util.java
/** * Decode the BASE64 encoded string./* w w w. java 2 s. com*/ * @param source The BASE64 string. * @return The decoded original string. */ public static String decodeBase64(String source) { try { return new String(Base64.decodeBase64(source), "UTF-8"); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } }
From source file:fr.eclipseonfire.mjapi.implementations.http.StandardMinecraftProperties.java
@Override public MinecraftTextures getTexturesProperty() throws IOException { Property property = this.getByName("textures"); if (property == null) { return null; }//w ww . j ava 2 s. c o m String json = new String(Base64.decodeBase64(property.getValue()), StandardCharsets.UTF_8); return HttpAccountRepository.GSON.fromJson(json, HttpMinecraftTextures.class); }
From source file:com.josue.jsf.jaxrs.base64.GenericResource.java
@GET @Produces("text/plain") public String getText(@QueryParam("query") String query) { byte[] decodedBytes = Base64.decodeBase64(query.getBytes()); StringTokenizer token = new StringTokenizer(new String(decodedBytes), "&"); Map<String, Object> params = new HashMap<>(); while (token.hasMoreElements()) { String keyVal = token.nextToken(); params.put(keyVal.split("=")[0], keyVal.split("=")[1]); }// ww w . ja va 2 s .c om for (Object o : params.values()) { LOG.info(o.toString()); } return new String(decodedBytes); }
From source file:com.mycollab.common.UrlEncodeDecoder.java
/** * @param str/*from www . ja v a2 s.c o m*/ * @return */ public static String decode(String str) { try { String decodeStr = URLDecoder.decode(str, "UTF8"); decodeStr = new String(Base64.decodeBase64(decodeStr.getBytes("UTF-8")), "UTF-8"); return decodeStr; } catch (Exception e) { LOG.error("Error while decode string: " + str); return ""; } }
From source file:io.druid.query.aggregation.datasketches.quantiles.DoublesSketchOperations.java
public static DoublesSketch deserializeFromBase64EncodedString(final String str) { return deserializeFromByteArray(Base64.decodeBase64(str.getBytes(StandardCharsets.UTF_8))); }
From source file:com.yahoo.yos.AccessToken.java
public AccessToken(Cookie cookie) throws UnsupportedEncodingException, JSONException { JSONObject json = new JSONObject( new String(Base64.decodeBase64(cookie.getValue().getBytes("UTF-8")), "UTF-8")); setKey(json.optString("key", null)); setSecret(json.optString("secret", null)); setGuid(json.optString("guid", null)); setOwner(json.optString("owner", null)); setTokenExpires(json.optLong("tokenExpires", -1)); setHandleExpires(json.optLong("handleExpires", -1)); setSessionHandle(json.optString("sessionHandle", null)); setConsumer(json.optString("consumer", null)); }
From source file:com.esofthead.mycollab.common.UrlEncodeDecoder.java
/** * /*from w w w . j a v a 2 s . co m*/ * @param str * @return */ static String decode(String str) { try { String decodeStr = URLDecoder.decode(str, "UTF8"); decodeStr = new String(Base64.decodeBase64(decodeStr.getBytes("UTF-8")), "UTF-8"); return decodeStr; } catch (Exception e) { LOG.error("Error while decode string: " + str); return ""; } }
From source file:net.shopxx.filter.AccessDeniedFilter.java
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletResponse response = (HttpServletResponse) servletResponse; response.addHeader(new String(Base64.decodeBase64("UG93ZXJlZEJ5"), "utf-8"), new String(Base64.decodeBase64("Y2hlbmd6aGFuZy5jbw=="), "utf-8")); response.sendError(HttpServletResponse.SC_FORBIDDEN, ERROR_MESSAGE); }
From source file:com.cloudera.director.google.TestFixture.java
public static TestFixture newTestFixture(boolean sshPublicKeyAndUserNameAreRequired) throws IOException { String projectId = TestUtils.readRequiredSystemProperty("GCP_PROJECT_ID"); String jsonKey = TestUtils.readFileIfSpecified(System.getProperty("JSON_KEY_PATH", "")); // If the path to a json key file was not provided, check if the key was passed explicitly. if (jsonKey == null) { String jsonKeyInline = System.getProperty("JSON_KEY_INLINE", ""); if (!jsonKeyInline.isEmpty()) { // If so, we must base64-decode it. jsonKey = new String(Base64.decodeBase64(jsonKeyInline)); }/* ww w. j a v a2 s .c om*/ } String sshPublicKey = null; String userName = null; if (sshPublicKeyAndUserNameAreRequired) { sshPublicKey = TestUtils.readFile(TestUtils.readRequiredSystemProperty("SSH_PUBLIC_KEY_PATH"), Charset.defaultCharset()); userName = TestUtils.readRequiredSystemProperty("SSH_USER_NAME"); } boolean haltAfterAllocation = Boolean.parseBoolean(System.getProperty("HALT_AFTER_ALLOCATION", "false")); return new TestFixture(projectId, jsonKey, sshPublicKey, userName, haltAfterAllocation); }
From source file:dk.nversion.jwt.CryptoUtils.java
public static PrivateKey loadPrivateKey(String filename) throws FileNotFoundException, IOException, InvalidKeySpecException, NoSuchAlgorithmException { PrivateKey key = null;//from w w w .j a va 2 s .c o m InputStream is = null; try { is = new FileInputStream(filename); BufferedReader br = new BufferedReader(new InputStreamReader(is)); StringBuilder builder = new StringBuilder(); boolean inKey = false; String line; while ((line = br.readLine()) != null) { if (!inKey) { if (line.startsWith("-----BEGIN PRIVATE KEY-----")) { inKey = true; } } else { if (line.startsWith("-----END PRIVATE KEY-----")) { break; } builder.append(line); } } byte[] encoded = Base64.decodeBase64(builder.toString()); PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(encoded); KeyFactory kf = KeyFactory.getInstance("RSA"); key = kf.generatePrivate(keySpec); } finally { if (is != null) { try { is.close(); } catch (IOException ex) { // Ignore } } } return key; }