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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations