List of usage examples for org.apache.commons.codec.binary Base64 Base64
public Base64()
From source file:com.sixsq.slipstream.cookie.CryptoUtils.java
static private void setKeyPairFromDb() throws NoSuchAlgorithmException, InvalidKeySpecException, CertificateException { CookieKeyPair ckp = CookieKeyPair.load(); if (ckp == null) { return;//from w w w .ja v a 2 s. c o m } String privateKeyBase64 = ckp.getPrivateKey(); String publicKeyBase64 = ckp.getPublicKey(); if (privateKeyBase64 == null || publicKeyBase64 == null) { return; } byte[] privateKeyBytes = new Base64().decode(privateKeyBase64); KeyFactory keyFactory = KeyFactory.getInstance(keyPairAlgorithm); KeySpec privateKeySpec = new PKCS8EncodedKeySpec(privateKeyBytes); privateKey = keyFactory.generatePrivate(privateKeySpec); byte[] publicKeyBytes = new Base64().decode(publicKeyBase64); X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(publicKeyBytes); keyFactory = KeyFactory.getInstance(keyPairAlgorithm); publicKey = keyFactory.generatePublic(x509KeySpec); }
From source file:com.sldeditor.common.property.EncryptedPropertiesApache.java
@Override public synchronized String encrypt(String str) { byte[] utf8;//from www.j av a 2 s.c om try { utf8 = str.getBytes("UTF-8"); byte[] enc = encrypter.doFinal(utf8); return new Base64().encodeToString(enc); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IllegalBlockSizeException e) { e.printStackTrace(); } catch (BadPaddingException e) { e.printStackTrace(); } return ""; }
From source file:com.google.gsa.valve.saml.SAMLArtifactProcessor.java
/** * Stores the artifact/* ww w .j av a 2 s .c o m*/ * * @param userName user name * * @return the artifact */ public static String storeArtifact(String userName) { long time = new Date().getTime() / MSECS_IN_SEC; Base64 base64 = new Base64(); String artifact = new String(base64.encode(createRandomHexString(20).getBytes())); logger.debug("storeArtifact: storing artifact (" + artifact + ") for user (" + userName + ") and time (" + new Long(time).toString() + ")"); createArtifactMap(artifact, userName, time); return artifact; }
From source file:info.jtrac.web.RestMultiActionController.java
private boolean authenticate(HttpServletRequest request) { String authHeader = request.getHeader("Authorization"); logger.debug("auth header: " + authHeader); if (authHeader == null) { return false; }// www . ja v a 2 s.c o m StringTokenizer st = new StringTokenizer(authHeader); if (st.hasMoreTokens()) { String basic = st.nextToken(); if (basic.equalsIgnoreCase("Basic")) { String credentials = st.nextToken(); Base64 decoder = new Base64(); String userPass = new String(decoder.decode(credentials.getBytes())); int p = userPass.indexOf(":"); if (p == -1) { return false; } String loginName = userPass.substring(0, p); String password = userPass.substring(p + 1); User user = jtrac.loadUser(loginName); if (user == null) { return false; } String encoded = jtrac.encodeClearText(password); if (user.getPassword().equals(encoded)) { request.setAttribute("user", user); return true; } } } return false; }
From source file:com.cilogi.aws.cart.SignRequests.java
/** * Compute the HMAC./*w w w.j a v a 2 s . c o m*/ * * @param stringToSign String to compute the HMAC over. * @return base64-encoded hmac value. */ private String hmac(String stringToSign) { try { byte[] data = stringToSign.getBytes(UTF8); byte[] rawHmac = mac.doFinal(data); Base64 encoder = new Base64(); return new String(encoder.encode(rawHmac)); } catch (UnsupportedEncodingException e) { throw new RuntimeException(UTF8 + " is unsupported!", e); } }
From source file:com.rutarget.UpsourceReviewStatsExtension.PageExtension.java
private static <T> T request(String method, @Nullable Object parameter, Class<T> clazz) throws IOException { String address = UPSOURCE_API_URL + method; URL url = new URL(address); @SuppressWarnings("ConstantConditions") HttpURLConnection c = (HttpURLConnection) (PROXY != null ? url.openConnection(PROXY) : url.openConnection());// w w w . j av a 2 s. c o m String authString = UPSOURCE_USERNAME + ":" + UPSOURCE_PASSWORD; //Base64 doesn't look thread safe, therefore we create new instance for each occasion c.setRequestProperty("Authorization", "Basic " + new String(new Base64().encode(authString.getBytes()))); if (parameter != null) { String output = GSON.toJson(parameter); c.setDoOutput(true); c.setRequestMethod("POST"); c.setRequestProperty("Content-Type", "application/json"); c.setRequestProperty("Content-Length", String.valueOf(output.length())); c.getOutputStream().write(output.getBytes("UTF-8")); } InputStream inputStream = c.getInputStream(); String response = IOUtils.toString(inputStream); try { JsonObject element = (JsonObject) new JsonParser().parse(response); return GSON.fromJson(element.get("result"), clazz); } catch (Exception e) { throw new IOException( "Failed to parse response " + escapeToHtmlAttribute(response) + ": " + e.getMessage()); } }
From source file:at.uni_salzburg.cs.ckgroup.apos.AposNtrip.java
/** * Construct an APOS NTRIP RTCM input stream. * /*from ww w .java 2 s .c o m*/ * @param ntripProperties the properties of the NTRIP connection to be used. * @throws IOException thrown if host or port number is invalid. */ public AposNtrip(Properties ntripProperties) throws IOException { String caster = ntripProperties.getProperty(PROP_CASTER); int port = Integer.parseInt(ntripProperties.getProperty(PROP_PORT)); String mountPoint = ntripProperties.getProperty(PROP_MOUNTPOINT); ntripCasterUrl = new URL("http", caster, port, mountPoint == null ? "/" : "/" + mountPoint); String userName = ntripProperties.getProperty(PROP_USERNAME); String password = ntripProperties.getProperty(PROP_PASSWORD); byte[] encodedPassword = (userName + ":" + password).getBytes(); Base64 encoder = new Base64(); basicAuthentication = encoder.encode(encodedPassword); }
From source file:com.hp.alm.ali.idea.cfg.AliConfiguration.java
public synchronized void loadState(Element element) { ALM_LOCATION = getProperty(element, PROPERTY_LOCATION); ALM_DOMAIN = getProperty(element, PROPERTY_DOMAIN); ALM_PROJECT = getProperty(element, PROPERTY_PROJECT); ALM_USERNAME = getProperty(element, PROPERTY_USERNAME); ALM_PASSWORD = new String(new Base64().decode(getProperty(element, PROPERTY_PASSWORD).getBytes())); STORE_PASSWORD = Boolean.valueOf(getProperty(element, PROPERTY_STORE_PASSWORD)); STATUS_TRANSITION = getProperty(element, PROPERTY_STATUS_TRANSITION); spellChecker = Boolean.valueOf(getProperty(element, PROPERTY_SPELL_CHECKER, "true")); devMotiveAnnotation = Boolean.valueOf(getProperty(element, PROPERTY_DEV_MOTIVE_ANNOTATION, "true")); Element stored = element.getChild("stored"); if (stored != null) { loadStoredFilters(stored);/*from w ww . ja va 2 s. c om*/ } }
From source file:com.bitplan.mjpegstreamer.MJpegRunnerBase.java
/** * get a Base64 Encoder/* w w w.j av a2 s .co m*/ * * @return the base 64 encoder */ public Base64 getEncoder() { // JDK 8 // Base64.Encoder base64 = Base64.getEncoder(); // Apache Commons codec Base64 base64 = new Base64(); return base64; }
From source file:com.gargoylesoftware.htmlunit.javascript.host.canvas.rendering.AwtRenderingBackend.java
/** * {@inheritDoc}//from w w w.ja v a 2 s .co m */ public String encodeToString(final String type) throws IOException { try (final ByteArrayOutputStream bos = new ByteArrayOutputStream()) { ImageIO.write(image_, type, bos); final byte[] imageBytes = bos.toByteArray(); return new String(new Base64().encode(imageBytes)); } }