Search in sources :

Example 41 with BASE64Encoder

use of sun.misc.BASE64Encoder in project topcom-cloud by 545314690.

the class RandomVerifyCode method getBase64Randcode.

/**
 * 生成随机图片,返回对应的base64编码
 */
public VerifyCode getBase64Randcode() {
    // BufferedImage类是具有缓冲区的Image类,Image类是用于描述图像信息的类
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
    // 产生Image对象的Graphics对象,改对象可以在图像上进行各种绘制操作
    Graphics g = image.getGraphics();
    g.fillRect(0, 0, width, height);
    g.setFont(new Font("Times New Roman", Font.ROMAN_BASELINE, 18));
    g.setColor(getRandColor(110, 133));
    // 绘制干扰线
    for (int i = 0; i <= lineSize; i++) {
        drowLine(g);
    }
    // 绘制随机字符
    String randomString = "";
    for (int i = 1; i <= stringNum; i++) {
        randomString = drowString(g, randomString, i);
    }
    g.dispose();
    try {
        ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(image);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        // 将内存中的图片通过流动形式输出到客户端
        ImageIO.write(image, "JPEG", outputStream);
        BASE64Encoder encoder = new BASE64Encoder();
        // 返回Base64编码过的字节数组字符串
        String imageStr = "data:image/png;base64," + encoder.encode(outputStream.toByteArray());
        return new VerifyCode(randomString, imageStr);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : Graphics(java.awt.Graphics) BASE64Encoder(sun.misc.BASE64Encoder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedImage(java.awt.image.BufferedImage) Font(java.awt.Font) ImageOutputStream(javax.imageio.stream.ImageOutputStream)

Example 42 with BASE64Encoder

use of sun.misc.BASE64Encoder in project CshBBrain by CshBBrain.

the class WebSocketDecoder method base64Encode.

public static String base64Encode(byte[] input) {
    BASE64Encoder encoder = new BASE64Encoder();
    String base64 = encoder.encode(input);
    return base64;
}
Also used : BASE64Encoder(sun.misc.BASE64Encoder)

Example 43 with BASE64Encoder

use of sun.misc.BASE64Encoder in project CshBBrain by CshBBrain.

the class ClustersDecoder method base64Encode.

public static String base64Encode(byte[] input) {
    BASE64Encoder encoder = new BASE64Encoder();
    String base64 = encoder.encode(input);
    return base64;
}
Also used : BASE64Encoder(sun.misc.BASE64Encoder)

Example 44 with BASE64Encoder

use of sun.misc.BASE64Encoder in project sakuli by ConSol.

the class ScreenshotDivConverter method extractScreenshotAsBase64.

protected String extractScreenshotAsBase64(Exception exception) {
    if (exception instanceof SakuliExceptionWithScreenshot) {
        Path screenshotPath = ((SakuliExceptionWithScreenshot) exception).getScreenshot();
        if (screenshotPath != null) {
            try {
                byte[] binaryScreenshot = Files.readAllBytes(screenshotPath);
                String base64String = new BASE64Encoder().encode(binaryScreenshot);
                for (String newLine : Arrays.asList("\n", "\r")) {
                    base64String = StringUtils.remove(base64String, newLine);
                }
                return base64String;
            } catch (IOException e) {
                exceptionHandler.handleException(new SakuliForwarderCheckedException(e, String.format("error during the BASE64 encoding of the screenshot '%s'", screenshotPath.toString())));
            }
        }
    }
    return null;
}
Also used : Path(java.nio.file.Path) BASE64Encoder(sun.misc.BASE64Encoder) SakuliExceptionWithScreenshot(org.sakuli.exceptions.SakuliExceptionWithScreenshot) IOException(java.io.IOException) SakuliForwarderCheckedException(org.sakuli.exceptions.SakuliForwarderCheckedException)

Example 45 with BASE64Encoder

use of sun.misc.BASE64Encoder in project sakuli by ConSol.

the class AesCbcCipher method encryptString.

public static String encryptString(String secret, SecretKey aesKey) throws SakuliCipherException {
    final SecureRandom rng = new SecureRandom();
    final byte[] ciphertext = encryptBytes(rng, aesKey, convertStringToBytes(secret));
    return new BASE64Encoder().encode(ciphertext);
}
Also used : BASE64Encoder(sun.misc.BASE64Encoder) SecureRandom(java.security.SecureRandom)

Aggregations

BASE64Encoder (sun.misc.BASE64Encoder)45 IOException (java.io.IOException)17 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 MessageDigest (java.security.MessageDigest)8 FileInputStream (java.io.FileInputStream)7 BufferedInputStream (java.io.BufferedInputStream)6 BufferedOutputStream (java.io.BufferedOutputStream)6 FileNotFoundException (java.io.FileNotFoundException)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 Map (java.util.Map)4 HostnameVerifier (javax.net.ssl.HostnameVerifier)4 SSLSession (javax.net.ssl.SSLSession)4 Call (org.apache.axis.client.Call)4 BASE64Decoder (sun.misc.BASE64Decoder)4 File (java.io.File)3 URL (java.net.URL)3 Signature (java.security.Signature)3 X509Certificate (java.security.cert.X509Certificate)3 Date (java.util.Date)3