use of sun.misc.BASE64Decoder in project carbon-business-process by wso2.
the class WorkflowServiceClient method decodeToImage.
private BufferedImage decodeToImage(String imageString) throws IOException {
BufferedImage image = null;
ByteArrayInputStream bis = null;
byte[] imageByte;
try {
BASE64Decoder decoder = new BASE64Decoder();
imageByte = decoder.decodeBuffer(imageString);
bis = new ByteArrayInputStream(imageByte);
image = ImageIO.read(bis);
} finally {
if (bis != null) {
try {
bis.close();
} catch (IOException e) {
log.error("Error occurred while closing the input stream", e);
}
}
}
return image;
}
use of sun.misc.BASE64Decoder in project javautils by jiadongpo.
the class RSAUtil method getPublicKey.
/**
* 得到公钥
*
* @param key
* 密钥字符串(经过base64编码)
* @throws Exception
*/
public static PublicKey getPublicKey(String key) throws Exception {
byte[] keyBytes;
keyBytes = (new BASE64Decoder()).decodeBuffer(key);
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PublicKey publicKey = keyFactory.generatePublic(keySpec);
return publicKey;
}
use of sun.misc.BASE64Decoder in project javautils by jiadongpo.
the class RSAUtil method getPrivateKey.
/**
* 得到私钥
*
* @param key
* 密钥字符串(经过base64编码)
* @throws Exception
*/
public static PrivateKey getPrivateKey(String key) throws Exception {
byte[] keyBytes;
keyBytes = (new BASE64Decoder()).decodeBuffer(key);
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
return privateKey;
}
use of sun.misc.BASE64Decoder in project javautils by jiadongpo.
the class RSAUtil method decrypt.
/**
* 使用私钥对明文密文进行解密
* @param privateKey
* @param enStr
* @return
*/
public static String decrypt(PrivateKey privateKey, String enStr) {
try {
cipher.init(Cipher.DECRYPT_MODE, privateKey);
byte[] deBytes = cipher.doFinal((new BASE64Decoder()).decodeBuffer(enStr));
return new String(deBytes);
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
use of sun.misc.BASE64Decoder in project PorkBot by DaMatrix.
the class CommandMcQuery method execute.
@Override
public void execute(MessageReceivedEvent evt, String[] args, String message) {
if (args.length < 2 || args[1].isEmpty()) {
sendErrorMessage(evt.getTextChannel(), "IP isn't given!");
return;
}
MCPing.Query query = null;
String[] ipPort = args[1].split(":");
if (ipPort.length == 1) {
query = MCPing.query(ipPort[0], 25565, false, true);
} else if (ipPort.length == 2) {
try {
query = MCPing.query(ipPort[0], Integer.parseInt(ipPort[1]), false, true);
} catch (NumberFormatException e) {
MessageUtils.sendMessage("Error getting server info: `java.lang.NumberFormatException`", evt.getTextChannel());
return;
}
} else {
MessageUtils.sendMessage("Unable to parse server ip!", evt.getTextChannel());
return;
}
if (query.status) {
if (query.noQuery) {
EmbedBuilder builder = new EmbedBuilder();
builder.setColor(Color.ORANGE);
builder.addField("**Unable to query**", "The server `" + args[1] + "` is online, but we were unable to query it. Make sure that `enable-query` is set to `true` in `server.properties` and that the server's port is open on UDP!", false);
MessageUtils.sendMessage(builder, evt.getTextChannel());
return;
} else {
EmbedBuilder builder = new EmbedBuilder();
builder.setColor(Color.GREEN);
String[] parts = query.favicon.split("\\,");
String imageString = parts[1];
byte[] imageByte = null;
BASE64Decoder decoder = new BASE64Decoder();
try {
imageByte = decoder.decodeBuffer(imageString);
} catch (IOException e) {
// whatever lol
}
builder.setThumbnail("attachment://image.png");
builder.addField("**" + args[1] + "**", "Status: ***ONLINE***", false);
builder.addField("Ping", query.ping, true);
builder.addField("Version", query.version, true);
builder.addField("Players", query.players, true);
builder.addField("MOTD", TextFormat.clean(query.motd), false);
builder.addField("Gamemode", query.gamemode, true);
builder.addField("World name", query.mapName, true);
if (query.playerSample != null && !query.playerSample.isEmpty()) {
builder.addField("Player sample", query.playerSample, false);
}
if (query.plugins != null && !query.plugins.isEmpty()) {
builder.addField("Plugins", query.plugins, false);
}
MessageUtils.sendImage(builder, imageByte, "image.png", evt.getTextChannel());
return;
}
} else {
if (query.noQuery) {
EmbedBuilder builder = new EmbedBuilder();
builder.setColor(Color.ORANGE);
builder.addField("**Unable to query**", "The server `" + args[1] + "` is online, but we were unable to query it. Make sure that `enable-query` is set to `true` in `server.properties` and that the server's port is open on UDP!", false);
MessageUtils.sendMessage(builder, evt.getTextChannel());
return;
} else {
EmbedBuilder builder = new EmbedBuilder();
builder.setColor(Color.RED);
builder.addField("**" + args[1] + "**", "Status: ***OFFLINE***", false);
MessageUtils.sendMessage(builder, evt.getTextChannel());
return;
}
}
}
Aggregations