加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Xfire 图片(image) webservice byte 加密 传输 ---- 上传

发布时间:2020-12-17 01:18:14 所属栏目:安全 来源:网络整理
导读:最近研究 xfire 进行文件传输,现提供BASE64 加密 byte流传输方法: https 及apache?调用方式 注意服务端xalan.jar包 ? 客户端: 1、byte[]?? buffer?? =?? image2Bytes("D:/Koala.jpg"); //读文件,转换为byte流 2、String encodedFileString = Base64.encode(

最近研究 xfire 进行文件传输,现提供BASE64 加密 byte流传输方法:

https 及apache?调用方式 注意服务端xalan.jar包

?

客户端:

1、byte[]?? buffer?? =?? image2Bytes("D:/Koala.jpg"); //读文件,转换为byte流

2、String encodedFileString = Base64.encode(buffer);//对数据流进行加密,需要注意的是此BASE64加密方法为import org.codehaus.xfire.util.Base64;包提供
??????buffer?? = Base64.decode(encodedFileString);

3、函数,里面提供两种方法

//将图片转成字节流
?public static byte[] image2Bytes(String imagePath) throws FileNotFoundException {

//? start
//??BufferedImage input = ImageIO.read(file1);
//??Image scaledImage = input.getScaledInstance(256,256,Image.SCALE_DEFAULT);
//??BufferedImage output = new BufferedImage(256,BufferedImage.TYPE_INT_BGR);
//??output.createGraphics().drawImage(scaledImage,null); //画图

//? end 这断方法 提供测试用 可直接将图片画出

?

//第一种方法,此方法不对图片进行任何改动
??File?? image?? =?? new?? File( imagePath);//读取文件路径,存文件
??InputStream is = new FileInputStream(image);
??byte[] buff = new byte[(int)image.length()];//文件大小??System.out.println("image.length()=="+image.length());
??

//第二种方法 对图片进行格式化
//??ImageIcon ima = new ImageIcon(imagePath);
//??int outputWidth = ima.getImage().getWidth(null);??
//??????? if (outputWidth < 1) {??
//??????????? throw new IllegalArgumentException("output image width " + outputWidth + " is out of range");??
//??????? }??
//??????? int outputHeight = ima.getImage().getHeight(null);??
//??????? if (outputHeight < 1) {??
//??????????? throw new IllegalArgumentException("output image height " + outputHeight + " is out of range");??
//??????? }??
//??BufferedImage bu = new BufferedImage(ima.getImage().getWidth(null),ima.getImage().getHeight(null),BufferedImage.TYPE_INT_RGB);
//??ByteArrayOutputStream imageStream = new ByteArrayOutputStream();


??try {
??????? //把这个jpg图像写到这个流中去,这里可以转变图片的编码格式
??????? //boolean resultWrite = ImageIO.write(bu,"png",imageStream);
?????? is.read(buff);
????? ?is.close();
??} catch (IOException e) {
???e.printStackTrace();
??}
? //byte[] tagInfo = imageStream.toByteArray();
??byte[] tagInfo = buff;
??return tagInfo;
? }

?

服务端

1、buffer?? = Base64.decode(encodedFileString);//服务端接收到加密串后进行解密

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读