html怎么给图片加密,实现图片加密

//coding=utf8

2 /**

3 * @Author: Sir

4 * @Created Time : 2020年12月18日 星期五 19时37分56秒

5 * @File Name: imagesecret.java

6 * @Description:java基础

7 * @Mail:1198875194@qq.com

8 */

9 import java.io.*;

10

11 public class imagesecret{

12 public static void main(String[] args){

13 FileInputStream filer= null;

14 FileOutputStream filew = null;

15 try{

16 filer = new FileInputStream("1.png");

17 filew = new FileOutputStream("3.png");

18 byte[] bbuf = new byte[1024];

19 int len;

20 while((len = filer.read()) != -1){

21 //对字节数据进行修改进行加密

22 for(int i = 0;i < len;i++){

23 bbuf[i] = (byte)(bbuf[i] ^ 5);

24 }

25 filew.write(bbuf,0,len);

26 }

27 }

28 catch(IOException e){

29 e.printStackTrace();

30 }

31 finally{

32 if(filer != null){

33 try{

34 filer.close();

35 }

36 catch(IOException e){

37 e.printStackTrace();

38 }

39 }

40 if(filew != null){

41 try{

42 filer.close();

43 }

44 catch(IOException e){

45 e.printStackTrace();

46 }

47 }

48 }

49 }

50 }

~

图片的解密

//coding=utf8

2 /**

3 * @Author: Sir

4 * @Created Time : 2020年12月18日 星期五 19时48分48秒

5 * @File Name: imagedeciphering.java

6 * @Description:java基础

7 * @Mail:1198875194@qq.com

8 */

9

10 import java.io.*;

11

12 public class imagedeciphering{

13 public static void main(String[] args){

14 FileInputStream filer= null;

15 FileOutputStream filew = null;

16 try{

17 filer = new FileInputStream("3.png");

18 filew = new FileOutputStream("4.png");

19 byte[] bbuf = new byte[1024];

20 int len;

21 while((len = filer.read()) != -1){

22 //对字节数据进行修改进行解密

23 for(int i = 0;i < len;i++){

24 bbuf[i] = (byte)(bbuf[i] ^ 5);

25 }

26 filew.write(bbuf,0,len);

27 }

28 }

29 catch(IOException e){

30 e.printStackTrace();

31 }

32 finally{

33 if(filer != null){

34 try{

35 filer.close();

36 }

37 catch(IOException e){

38 e.printStackTrace();

39 }

40 }

41 if(filew != null){

42 try{

43 filer.close();

44 }

45 catch(IOException e){

46 e.printStackTrace();

47 }

48 }

49 }

50 }

51 }

在学习java中记录一下,若有错误请见谅。

标签:filer,加密,java,实现,bbuf,len,filew,null,图片

来源: https://www.cnblogs.com/zoutingrong/p/14156779.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值