List of usage examples for org.apache.commons.codec.binary Base64 Base64
public Base64()
From source file:com.ibm.watson.developer_cloud.professor_languo.ingestion.indexing.WatsonSolrClient.java
/** * Include authentication info in execute method *///w w w.j a v a2s.c om @Override protected NamedList<Object> executeMethod(HttpRequestBase method, ResponseParser parser) throws SolrServerException { Base64 b = new Base64(); String encoded = b.encodeAsString(new String(userPass).getBytes()); method.setHeader(new BasicHeader("Authorization", "Basic " + encoded)); return super.executeMethod(method, parser); }
From source file:com.palominolabs.crm.sf.rest.PicklistEntry.java
@JsonCreator PicklistEntry(@JsonProperty("value") String value, @JsonProperty("active") boolean active, @JsonProperty("label") String label, @JsonProperty("defaultValue") boolean defaultValue, @Nullable @JsonProperty("validFor") String validFor) { this.value = value; this.active = active; this.label = label; this.defaultValue = defaultValue; if (validFor == null) { this.validFor = new ImmutableBitSet(new BitSet()); } else {//ww w . j av a 2 s. co m //validFor is in base64 Base64 base64 = new Base64(); byte[] decoded = base64.decode(validFor); this.validFor = ImmutableBitSets.parseValidForBytes(decoded); } }
From source file:com.eviware.soapui.support.xml.actions.InsertBase64FileTextAreaAction.java
public void actionPerformed(ActionEvent e) { File file = UISupport.getFileDialogs().open(this, dialogTitle, null, null, null); if (file == null) return;//from ww w . j a v a 2 s .com try { // read file byte[] ba = FileUtils.readFileToByteArray(file); // convert to base 64 Base64 b64 = new Base64(); String hex = new String(b64.encode(ba)); // insert into text at cursor position int pos = textArea.getCaretPosition(); StringBuffer text = new StringBuffer(textArea.getText()); text.insert(pos, hex); textArea.setText(text.toString()); } catch (IOException e1) { UISupport.showErrorMessage("Error reading from file: " + e1.getMessage()); } }
From source file:de.openflorian.crypt.provider.XorCipher.java
@Override public String encrypt(String plain) throws GeneralSecurityException { if (StringUtils.isEmpty(plain)) throw new IllegalArgumentException("String AND Key may not be empty."); if (StringUtils.isEmpty(key)) throw new IllegalStateException("Xor cipher key is not set."); char[] keychars = key.toCharArray(); char[] targetchars = plain.toCharArray(); int keycharsLength = keychars.length, targetcharsLength = targetchars.length; char[] newtarget = new char[targetcharsLength]; for (int i = 0; i < targetcharsLength; i++) newtarget[i] = (char) (targetchars[i] ^ keychars[i % keycharsLength]); keychars = null;//from w ww .j a v a 2s . co m targetchars = null; try { return new String(new Base64().encode(new String(newtarget).getBytes("UTF-8"))); } catch (UnsupportedEncodingException e) { throw new GeneralSecurityException(e); } }
From source file:edu.harvard.iq.dvn.core.admin.PasswordEncryption.java
public synchronized String encrypt(String plaintext) { MessageDigest md = null;// w w w . j ava2 s. co m try { md = MessageDigest.getInstance("SHA"); //step 2 } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } try { md.update(plaintext.getBytes("UTF-8")); //step 3 } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } byte[] raw = md.digest(); //step 4 try { String hash = new String(new Base64().encode(raw), "ASCII"); //step 5 return hash; //step 6 } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:Exporters.SaveFileExporter.java
public Element getVulnAsElement(Vulnerability vuln, Document doc) { Base64 b64 = new Base64(); Element vulnElement = doc.createElement("vuln"); if (vuln.isIs_custom_risk() == false) { vulnElement.setAttribute("custom-risk", "false"); vulnElement.setAttribute("cvss", vuln.getCvss_vector_string()); } else {/*from w ww. ja v a2 s .co m*/ vulnElement.setAttribute("custom-risk", "true"); } vulnElement.setAttribute("category", vuln.getRisk_category()); vulnElement.setAttribute("risk-score", "" + vuln.getRiskScore()); Element vulnTitle = doc.createElement("title"); vulnTitle.appendChild(doc.createTextNode(b64.encodeAsString(vuln.getTitle().getBytes()))); Element identifiersElement = doc.createElement("identifiers"); HashMap identifiersMap = vuln.getIdentifiers(); Iterator it = identifiersMap.keySet().iterator(); while (it.hasNext()) { String hashed_title = (String) it.next(); String import_tool = (String) identifiersMap.get(hashed_title); // add a tag mofo! Element identifier = doc.createElement("identifier"); identifier.setAttribute("hash", hashed_title); identifier.setAttribute("import_tool", import_tool); identifiersElement.appendChild(identifier); } Element vulnDescription = doc.createElement("description"); vulnDescription.appendChild(doc.createTextNode(b64.encodeAsString(vuln.getDescription().getBytes()))); Element vulnRecommendation = doc.createElement("recommendation"); vulnRecommendation.appendChild(doc.createTextNode(b64.encodeAsString(vuln.getRecommendation().getBytes()))); //TODO Fill out <References> tag Element vulnReferences = doc.createElement("references"); Enumeration refs_enums = vuln.getReferences().elements(); while (refs_enums.hasMoreElements()) { Reference ref = (Reference) refs_enums.nextElement(); Element vulnReference = doc.createElement("reference"); vulnReference.setAttribute("description", ref.getDescription()); vulnReference.appendChild(doc.createTextNode(ref.getUrl())); vulnReferences.appendChild(vulnReference); } Element affectedHosts = doc.createElement("affected-hosts"); Enumeration enums = vuln.getAffectedHosts().elements(); while (enums.hasMoreElements()) { Host host = (Host) enums.nextElement(); // Create all the lovely element nodes Element affectedHost = doc.createElement("host"); Element ipAddress = doc.createElement("ip-address"); if (host.getIp_address() != null) { ipAddress.appendChild(doc.createTextNode(host.getIp_address())); } Element hostname = doc.createElement("hostname"); if (host.getHostname() != null) { hostname.appendChild(doc.createTextNode(host.getHostname())); } Element netbios = doc.createElement("netbios-name"); if (host.getNetbios_name() != null) { netbios.appendChild(doc.createTextNode(host.getNetbios_name())); } Element os = doc.createElement("operating-system"); if (host.getOperating_system() != null) { os.appendChild(doc.createTextNode(host.getOperating_system())); } Element macAddress = doc.createElement("mac-address"); if (host.getMac_address() != null) { macAddress.appendChild(doc.createTextNode(host.getMac_address())); } Element portnumber = doc.createElement("portnumber"); if (host.getPortnumber() != null) { portnumber.appendChild(doc.createTextNode(host.getPortnumber())); } Element protocol = doc.createElement("protocol"); if (host.getProtocol() != null) { protocol.appendChild(doc.createTextNode(host.getProtocol())); } Element note = doc.createElement("note"); if (host.getNotes() != null) { Note n = host.getNotes(); note.appendChild(doc.createTextNode(b64.encodeAsString(n.getNote_text().getBytes()))); } // Append them to the affected Host node affectedHost.appendChild(ipAddress); affectedHost.appendChild(hostname); affectedHost.appendChild(netbios); affectedHost.appendChild(os); affectedHost.appendChild(macAddress); affectedHost.appendChild(portnumber); affectedHost.appendChild(protocol); affectedHost.appendChild(note); // Add that host to the affected hosts node affectedHosts.appendChild(affectedHost); } vulnElement.appendChild(vulnTitle); vulnElement.appendChild(identifiersElement); vulnElement.appendChild(vulnDescription); vulnElement.appendChild(vulnRecommendation); vulnElement.appendChild(vulnReferences); vulnElement.appendChild(affectedHosts); return vulnElement; }
From source file:io.gs2.model.BasicGs2Credential.java
@Override public void authorized(HttpUriRequest request, String service, String module, String function, Long timestamp) { String sign = new Base64().encodeAsString(SignUtil.sign(getClientSecret(), module, function, timestamp)); request.setHeader("X-GS2-CLIENT-ID", getClientId()); request.setHeader("X-GS2-REQUEST-TIMESTAMP", String.valueOf(timestamp)); request.setHeader("X-GS2-REQUEST-SIGN", sign); }
From source file:net.bioclipse.cdk.ui.sdfeditor.CDKFingerPrintPropertyCalculator.java
public BitSet parse(String value) { // TODO check if this is right byte[] bytes = new Base64().decode(value.getBytes()); BitSet set = new BitSet(); for (int i = 0; i < bytes.length * 8; i++) { if ((bytes[bytes.length - i / 8 - 1] & (1 << (i % 8))) > 0) { set.set(i);//from ww w. j av a2 s .c o m } } return set; }
From source file:cfa.vo.interop.EncodeDoubleArray.java
public static String encodeBase64(double[] data, boolean swapByteOrder) throws IOException { byte[] decodedData = doubleToByte(data); if (swapByteOrder) { ByteBuffer buf = ByteBuffer.wrap(decodedData); buf = buf.order(ByteOrder.LITTLE_ENDIAN); buf.get(decodedData);// w w w. ja v a 2s.co m } Base64 codec = new Base64(); byte[] encodedData = codec.encode(decodedData); String result = new String(encodedData); return result; }
From source file:be.wolkmaan.klimtoren.security.encryption.pbe.StandardPBEStringEncryptor.java
private StandardPBEStringEncryptor(final StandardPBEByteEncryptor standardPBEByteEncryptor) { super();//ww w. ja va 2s .co m this.byteEncryptor = standardPBEByteEncryptor; this.base64 = new Base64(); }