List of usage examples for org.apache.commons.codec.binary Base64 decodeBase64
public static byte[] decodeBase64(final byte[] base64Data)
From source file:com.boulmier.machinelearning.jobexecutor.encrypted.AES.java
public String decrypt(String strToDecrypt) { try {// ww w . j a v a 2s . c om Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING"); cipher.init(Cipher.DECRYPT_MODE, secretKey); return (new String(cipher.doFinal(Base64.decodeBase64(strToDecrypt)))); } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException e) { System.out.println("Error while decrypting: " + e.toString()); } return null; }
From source file:com.github.tell.codec.Base64Serializer.java
public Serializable decode(final byte[] encoded) throws IOException, ClassNotFoundException { final byte[] decoded = Base64.decodeBase64(encoded); final ByteArrayInputStream bais = new ByteArrayInputStream(decoded); final ObjectInputStream ois = new ObjectInputStream(bais); return (Serializable) ois.readObject(); }
From source file:com.mirth.connect.plugins.httpauth.basic.BasicAuthenticator.java
@Override public AuthenticationResult authenticate(RequestInfo request) { BasicHttpAuthProperties properties = getReplacedProperties(request); List<String> authHeaderList = request.getHeaders().get(HttpHeader.AUTHORIZATION.asString()); if (CollectionUtils.isNotEmpty(authHeaderList)) { String authHeader = StringUtils.trimToEmpty(authHeaderList.iterator().next()); int index = authHeader.indexOf(' '); if (index > 0) { String method = authHeader.substring(0, index); if (StringUtils.equalsIgnoreCase(method, "Basic")) { // Get Base64-encoded credentials String credentials = StringUtils.trim(authHeader.substring(index)); // Get the raw, colon-separated credentials credentials = new String(Base64.decodeBase64(credentials), StandardCharsets.ISO_8859_1); // Split on ':' to get the username and password index = credentials.indexOf(':'); if (index > 0) { String username = credentials.substring(0, index); String password = credentials.substring(index + 1); // Return successful result if the passwords match if (StringUtils.equals(password, properties.getCredentials().get(username))) { return AuthenticationResult.Success(username, properties.getRealm()); }//from w w w . j a v a 2s.c o m } } } } // Return authentication challenge return AuthenticationResult.Challenged("Basic realm=\"" + properties.getRealm() + "\""); }
From source file:net.duckling.ddl.web.agent.util.AuthUtil.java
private static String decodeAuth(String auth) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException { SecretKeySpec spec = new SecretKeySpec(getKey(), "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, spec); byte[] result = cipher.doFinal(Base64.decodeBase64(auth)); return new String(result, "UTF-8"); }
From source file:enc_mods.aes.java
public String getDecryptedString(String str) { String decrypted = ""; try {//from w w w . ja v a2 s.c om cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING"); cipher.init(Cipher.DECRYPT_MODE, secretkey); decrypted = new String(cipher.doFinal(Base64.decodeBase64(str))); } catch (Exception e) { e.printStackTrace(); } return decrypted; }
From source file:com.cnaude.purpleirc.IRCListeners.NoticeListener.java
/** * * @param event//from w w w . jav a 2 s . c om */ @Override public void onNotice(NoticeEvent event) { Channel channel = event.getChannel(); String message = event.getMessage().trim(); String notice = event.getNotice(); User user = event.getUser(); String nick = user.getNick(); if (message.startsWith(PurpleIRC.LINK_CMD) && ircBot.botLinkingEnabled) { String encodedText = message.replace(PurpleIRC.LINK_CMD, ""); String decodedText = new String(Base64.decodeBase64(encodedText.getBytes())); String splitMsg[] = decodedText.split(":"); plugin.logDebug("REMOTE LINK COMMAND: " + encodedText + "(" + decodedText + ")"); if (splitMsg.length >= 2) { String command = splitMsg[0]; String code = splitMsg[1]; if (command.equals("LINK_REQUEST")) { ircBot.linkRequests.put(user.getNick(), code); plugin.broadcastToGame(ChatColor.LIGHT_PURPLE + "PurpleIRC bot link request from " + ChatColor.WHITE + user.getNick(), "irc.link"); plugin.broadcastToGame(ChatColor.LIGHT_PURPLE + "To accept: " + ChatColor.WHITE + "/irc linkaccept " + ircBot.getFileName().replace(".yml", "") + " " + user.getNick(), "irc.link"); return; } plugin.logDebug("Are we linked to " + user.getNick() + "?"); if (ircBot.botLinks.containsKey(nick)) { plugin.logDebug("Yes we are linked. Is the code correct?"); if (ircBot.botLinks.get(nick).equals(code)) { plugin.logDebug("Yes the code is correct!"); plugin.logDebug(" [COMMAND: " + command + "]"); plugin.logDebug(" [CODE: " + code + "]"); if (command.equals("PRIVATE_MSG") && splitMsg.length >= 5) { String from = splitMsg[2]; String target = splitMsg[3]; String sMessage = decodedText.split(":", 5)[4]; plugin.logDebug(" [FROM:" + from + "]"); plugin.logDebug(" [TO:" + target + "]"); plugin.logDebug(" [MSG: " + sMessage + "]"); ircBot.playerCrossChat(user, from, target, sMessage); } else if (command.equals("PLAYER_INFO") && splitMsg.length >= 4) { String curCount = splitMsg[2]; String maxCount = splitMsg[3]; String players = ""; if (splitMsg.length == 5) { players = splitMsg[4]; } plugin.logDebug(" [CUR_COUNT:" + curCount + "]"); plugin.logDebug(" [MAX_COUNT:" + maxCount + "]"); plugin.logDebug(" [PLAYERS:" + players + "]"); if (!ircBot.remoteServerInfo.containsKey(nick)) { ircBot.remoteServerInfo.put(nick, new CaseInsensitiveMap<String>()); } if (ircBot.remoteServerInfo.containsKey(nick)) { ircBot.remoteServerInfo.get(nick).put("CUR_COUNT", curCount); ircBot.remoteServerInfo.get(nick).put("MAX_COUNT", maxCount); } if (!ircBot.remotePlayers.containsKey(nick)) { ircBot.remotePlayers.put(nick, new ArrayList<String>()); } if (ircBot.remotePlayers.containsKey(nick)) { ircBot.remotePlayers.get(nick).clear(); if (!players.isEmpty()) { for (String s : players.split(",")) { plugin.logDebug(" [ADDING:" + s + "]"); ircBot.remotePlayers.get(nick).add(s); } } } } } else { plugin.logDebug("Invalid code from " + nick + "!"); } } else { plugin.logDebug("We are not linked to " + nick + "!"); } } return; } plugin.logInfo("-" + user.getNick() + "-" + message); if (channel != null) { if (ircBot.isValidChannel(channel.getName())) { ircBot.broadcastIRCNotice(user, message, notice, channel); } } }
From source file:com.reydentx.core.common.JSONUtils.java
private static BufferedImage decodeToImage(String imageString) { BufferedImage image = null;//from w w w . j a va2s. com byte[] imageByte; try { imageByte = Base64.decodeBase64(imageString); ByteArrayInputStream bis = new ByteArrayInputStream(imageByte); image = ImageIO.read(bis); bis.close(); } catch (Exception e) { e.printStackTrace(); } return image; }
From source file:com.asual.lesscss.ResourcePackage.java
public static ResourcePackage fromString(String source) { if (!StringUtils.isEmpty(source)) { try {//from w w w .ja v a 2 s . c o m String key; String path = null; String extension = null; int slashIndex = source.lastIndexOf("/"); int dotIndex = source.lastIndexOf("."); if (dotIndex != -1 && slashIndex < dotIndex) { extension = source.substring(dotIndex + 1); path = source.substring(0, dotIndex); } else { path = source; } if (extension != null && !extensions.contains(extension)) { return null; } String[] parts = path.replaceFirst("^/", "").split(SEPARATOR); if (cache.containsValue(source)) { key = getKeyFromValue(cache, source); } else { key = parts[parts.length - 1]; byte[] bytes = null; try { bytes = Base64.decodeBase64(key.getBytes(ENCODING)); bytes = inflate(bytes); } catch (Exception e) { } key = new String(bytes, ENCODING); } String[] data = key.split(NEW_LINE); ResourcePackage rp = new ResourcePackage((String[]) ArrayUtils.subarray(data, 1, data.length)); int mask = Integer.valueOf(data[0]); if ((mask & NAME_FLAG) != 0) { rp.setName(parts[0]); } if ((mask & VERSION_FLAG) != 0) { rp.setVersion(parts[rp.getName() != null ? 1 : 0]); } rp.setExtension(extension); return rp; } catch (Exception e) { } } return null; }
From source file:fr.xebia.demo.amazon.aws.AmazonAwsInfrastructureMakerTest.java
void test_generate_user_data(Distribution distribution) { AmazonAwsInfrastructureMaker maker = new AmazonAwsInfrastructureMaker(); DBInstance dbInstance = new DBInstance() // .withEndpoint(new Endpoint() // .withAddress("my-db-host") // .withPort(3306) // ) ///* ww w. j a v a 2s . co m*/ .withMasterUsername("travel"); String userData = maker.buildUserData(distribution, dbInstance, "travel", "travel", "http://example.com/the/path/to/my/test-war-1.2.3.war"); System.out.println(distribution); System.out.println(new String(Base64.decodeBase64(userData))); }
From source file:com.kscs.server.web.source.XMLSourceCode.java
public static String getHibernateFrame() { return new String(Base64.decodeBase64(HIBERNATE_FRAME.getBytes())); }