List of usage examples for org.apache.commons.codec.binary Base64 decodeBase64
public static byte[] decodeBase64(final byte[] base64Data)
From source file:com.mindquarry.desktop.preferences.profile.Profile.java
public static String decodeBase64(String text) { try {/*from ww w.j a v a 2 s . c o m*/ return new String(Base64.decodeBase64(text.getBytes("UTF-8")), "UTF-8"); } catch (UnsupportedEncodingException e) { return new String(Base64.decodeBase64(text.getBytes())); } }
From source file:com.kbotpro.cache.xml.XMLParser.java
public Object getValue(Element element) { final String type = element.getAttributeValue("type"); if (type == null) { return null; }/*w ww . j a v a2 s .c o m*/ if (element.getText() == null) { return null; } if (type.equals("int")) { return Integer.parseInt(element.getText()); } if (type.equals("long")) { return Long.parseLong(element.getText()); } if (type.equals("double")) { return Double.parseDouble(element.getText()); } if (type.equals("float")) { return Float.parseFloat(element.getText()); } if (type.equals("boolean")) { return Boolean.parseBoolean(element.getText()); } if (type.equals("base64")) { return Base64.decodeBase64(element.getText()); } if (type.equals("string")) { return element.getText(); } if (type.equals("null")) { return null; } return null; }
From source file:com.aqnote.shared.cryptology.cert.tool.PrivateKeyTool.java
private static byte[] getKeyEncoded(String base64KeyFile) { if (StringUtils.isEmpty(base64KeyFile)) { return null; }// w w w . j ava 2s .c om String tmpBase64KeyFile = base64KeyFile; String headLine = BEGIN_KEY + lineSeparator; if (base64KeyFile.startsWith(headLine)) { tmpBase64KeyFile = StringUtils.removeStart(base64KeyFile, headLine); } headLine = BEGIN_KEY + "\r\n"; if (base64KeyFile.startsWith(headLine)) { tmpBase64KeyFile = StringUtils.removeStart(base64KeyFile, headLine); } if (tmpBase64KeyFile.endsWith(END_KEY)) { tmpBase64KeyFile = StringUtils.removeEnd(base64KeyFile, END_KEY); } return Base64.decodeBase64(tmpBase64KeyFile); }
From source file:com.zimbra.common.auth.twofactor.TOTPAuthenticator.java
private byte[] decode(String secret, Encoding encoding) throws ServiceException { byte[] decoded; switch (encoding) { case BASE32:// ww w . j a va2 s.c o m decoded = new Base32().decode(secret); break; case BASE64: decoded = Base64.decodeBase64(secret); break; default: throw ServiceException.FAILURE("unknown encoding", new Throwable()); } return decoded; }
From source file:com.hi3project.dandelion.util.properties.ImageProperty.java
private byte[] decodeImage(String imageData) { return Base64.decodeBase64(imageData.getBytes()); }
From source file:hws.core.JobMaster.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("app-id").withDescription("String of the Application Id ") .hasArg().withArgName("AppId").create("aid")); options.addOption(OptionBuilder.withLongOpt("load").withDescription("load module pipeline").hasArg() .withArgName("Json-Base64").create()); options.addOption(OptionBuilder.withLongOpt("remove").withDescription("remove modules").hasArgs() .withArgName("ModuleNames").create("rm")); options.addOption(OptionBuilder.withLongOpt("zk-servers").withDescription("List of the ZooKeeper servers") .hasArgs().withArgName("zkAddrs").create("zks")); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); String appIdStr = null;/*from ww w. j a v a 2s . co m*/ String modulePipelineBase64 = null; String modulePipelineJson = null; ModulePipeline modulePipeline = null; String[] moduleNames = null; if (cmd.hasOption("aid")) { appIdStr = cmd.getOptionValue("aid"); } String zksArgs = ""; String[] zkServers = null; if (cmd.hasOption("zks")) { zksArgs = "-zks"; zkServers = cmd.getOptionValues("zks"); for (String zks : zkServers) { zksArgs += " " + zks; } } if (cmd.hasOption("load")) { modulePipelineBase64 = cmd.getOptionValue("load"); modulePipelineJson = StringUtils.newStringUtf8(Base64.decodeBase64(modulePipelineBase64)); modulePipeline = Json.loads(modulePipelineJson, ModulePipeline.class); } else if (cmd.hasOption("rm")) { moduleNames = cmd.getOptionValues("rm"); } JobMaster master = new JobMaster(modulePipeline, appIdStr, zksArgs, zkServers); if (modulePipelineJson != null) { Logger.info("Module Pipeline: " + modulePipelineJson); Logger.info("Instances: " + Json.dumps(modulePipeline.instances())); } master.runMainLoop(); }
From source file:com.elle.analyster.admissions.AESCrypt.java
public static String decrypt(String key, String initVector, String encrypted) { try {/*from w w w .jav a2 s . c om*/ IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8")); SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING"); cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv); byte[] original = cipher.doFinal(Base64.decodeBase64(encrypted)); return new String(original); } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:de.betterform.xml.xforms.ui.UploadTest.java
/** * Tests ui element state.//from w w w .j a v a2 s . c o m * * @throws Exception if any error occurred during the test. */ public void testUploadBase64() throws Exception { Upload upload = (Upload) this.xformsProcesssorImpl.getContainer().lookup("upload-base64"); upload.getTarget().addEventListener(XFormsEventNames.VALUE_CHANGED, this.valueChangedListener, false); String filename = "UploadTest.xhtml"; String mediatype = "application/xhtml+xml"; BufferedInputStream bis = new BufferedInputStream(getClass().getResourceAsStream(filename)); byte[] data = new byte[bis.available()]; bis.read(data); upload.setValue(data, filename, mediatype); upload.getTarget().removeEventListener(XFormsEventNames.VALUE_CHANGED, this.valueChangedListener, false); assertEquals(new String(data), new String(Base64.decodeBase64(((String) upload.getValue()).getBytes()))); assertEquals(filename, upload.getFilename().getValue()); assertEquals(mediatype, upload.getMediatype().getValue()); ModelItem modelItem = upload.getModel().getInstance(upload.getInstanceId()) .getModelItem(upload.getInstanceNode()); assertEquals(filename, modelItem.getFilename()); assertEquals(mediatype, modelItem.getMediatype()); assertEquals("upload-base64", this.valueChangedListener.getId()); }
From source file:com.creditcloud.common.security.impl.DESTextCipher.java
@Override public String decrypt(String value) throws GeneralSecurityException { return new String(decryptCipher.doFinal(Base64.decodeBase64(value.getBytes()))); }
From source file:Authentication.HashPassword.java
public String decrypt(String encryptedString) { String decryptedText = null;/* w w w . j a v a 2s .co m*/ try { cipher.init(Cipher.DECRYPT_MODE, key); byte[] encryptedText = Base64.decodeBase64(encryptedString); byte[] plainText = cipher.doFinal(encryptedText); decryptedText = new String(plainText); } catch (Exception e) { e.printStackTrace(); } return decryptedText; }