Search in sources :

Example 11 with BASE64Decoder

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;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) BASE64Decoder(sun.misc.BASE64Decoder) BufferedImage(java.awt.image.BufferedImage)

Example 12 with BASE64Decoder

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;
}
Also used : PublicKey(java.security.PublicKey) X509EncodedKeySpec(java.security.spec.X509EncodedKeySpec) BASE64Decoder(sun.misc.BASE64Decoder) KeyFactory(java.security.KeyFactory)

Example 13 with BASE64Decoder

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;
}
Also used : PrivateKey(java.security.PrivateKey) PKCS8EncodedKeySpec(java.security.spec.PKCS8EncodedKeySpec) BASE64Decoder(sun.misc.BASE64Decoder) KeyFactory(java.security.KeyFactory)

Example 14 with BASE64Decoder

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;
}
Also used : IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) BadPaddingException(javax.crypto.BadPaddingException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException) BASE64Decoder(sun.misc.BASE64Decoder)

Example 15 with BASE64Decoder

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;
        }
    }
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) MCPing(net.daporkchop.porkbot.util.mcpinger.MCPing) IOException(java.io.IOException) BASE64Decoder(sun.misc.BASE64Decoder)

Aggregations

BASE64Decoder (sun.misc.BASE64Decoder)44 IOException (java.io.IOException)23 ByteArrayInputStream (java.io.ByteArrayInputStream)6 FileOutputStream (java.io.FileOutputStream)6 HashMap (java.util.HashMap)6 OutputStream (java.io.OutputStream)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 JSONObject (com.alibaba.fastjson.JSONObject)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 InvalidKeyException (java.security.InvalidKeyException)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 BASE64Encoder (sun.misc.BASE64Encoder)4 UserInfoServiceException (com.itrus.portal.exception.UserInfoServiceException)3 FileNotFoundException (java.io.FileNotFoundException)3 URL (java.net.URL)3 KeyFactory (java.security.KeyFactory)3 CertificateException (java.security.cert.CertificateException)3 Map (java.util.Map)3 Cipher (javax.crypto.Cipher)3