一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|

服務(wù)器之家 - 編程語言 - JAVA教程 - Java實現(xiàn)url加密處理的方法示例

Java實現(xiàn)url加密處理的方法示例

2020-11-05 15:56qq7342272 JAVA教程

這篇文章主要介紹了Java實現(xiàn)url加密處理的方法,涉及java基于base64、編碼轉(zhuǎn)換實現(xiàn)加密解密相關(guān)操作技巧,需要的朋友可以參考下

本文實例講述了Java實現(xiàn)url加密處理的方法。分享給大家供大家參考,具體如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package test;
import java.security.Key;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class ThreeDES {
  public static String crypt(String content,String password,int i){
    try {
      KeyGenerator generator = KeyGenerator.getInstance("AES");
      generator.init(new SecureRandom(password.getBytes()));
      Key key = generator.generateKey();
      generator = null;
      if(i == 1){
        return getEncString(content,key);
      }
      else if(i == 2){
        return getDesString(content,key);
      }
    } catch (Exception e) {
      return null;
    }
    return null;
  }
  /**
   * 加密String明文輸入,String密文輸出
   *
   * @param strMing
   * @return
   */
  private static String getEncString(String strMing,Key key) {
    byte[] byteMi = null;
    byte[] byteMing = null;
    String strMi = "";
    BASE64Encoder base64en = new BASE64Encoder();
    try {
      byteMing = strMing.getBytes("UTF8");
      byteMi = getEncCode(byteMing,key);
      strMi = base64en.encode(byteMi);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      base64en = null;
      byteMing = null;
      byteMi = null;
    }
    return strMi;
  }
  /**
   * 解密 以String密文輸入,String明文輸出
   *
   * @param strMi
   * @return
   */
  private static String getDesString(String strMi, Key key) {
    BASE64Decoder base64De = new BASE64Decoder();
    byte[] byteMing = null;
    byte[] byteMi = null;
    String strMing = "";
    try {
      byteMi = base64De.decodeBuffer(strMi);
      byteMing = getDesCode(byteMi,key);
      strMing = new String(byteMing, "UTF8");
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      base64De = null;
      byteMing = null;
      byteMi = null;
    }
    return strMing;
  }
  /**
   * 加密以byte[]明文輸入,byte[]密文輸出
   *
   * @param byteS
   * @return
   */
  private static byte[] getEncCode(byte[] byteS,Key key) {
    byte[] byteFina = null;
    Cipher cipher;
    try {
      cipher = Cipher.getInstance("AES");
      cipher.init(Cipher.ENCRYPT_MODE, key);
      byteFina = cipher.doFinal(byteS);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      cipher = null;
    }
    return byteFina;
  }
  /**
   * 解密以byte[]密文輸入,以byte[]明文輸出
   *
   * @param byteD
   * @return
   */
  private static byte[] getDesCode(byte[] byteD,Key key) {
    Cipher cipher;
    byte[] byteFina = null;
    try {
      cipher = Cipher.getInstance("AES");
      cipher.init(Cipher.DECRYPT_MODE, key);
      byteFina = cipher.doFinal(byteD);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      cipher = null;
    }
    return byteFina;
  }
  public static void main(String[] args) {
    System.out.println(ThreeDES.crypt("bindMobile=13023130171&fenjihao=107", "bbbbb", 1));
    System.out.println(ThreeDES.crypt("GT+F0fcFNGiq73/+FaX9pK9n9zqxwqz9sZ7MQdSp1BxWJXWn7EwnvniQpAOaGi0W", "bbbbb", 2));
  }
}

希望本文所述對大家java程序設(shè)計有所幫助。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产精品国产国产aⅴ | 公交车高h | 好大用力深一点女公交车 | 俄罗斯美女尿尿 | 国产视频一区二区 | 好舒服好爽再快点视频 | 精品免费看 | 亚洲 综合 自拍 精品 在线 | 国产精品国产国产aⅴ | 91在线老师啪国自产 | 欧美一区二区福利视频 | 天选之王漫画顾长歌免费阅读 | 国产一区二区视频在线播放 | 日本hd18| 免费观看欧美一级高清 | 国产免费小视频在线观看 | 9966久久精品免费看国产 | 国语视频高清在线观看 | aⅴ天堂小视频 | 女人pp被扒开流水了 | 北条麻妃一区 | 91精品久久一区二区三区 | 99re这里只有精品视频 | 成年人视频在线 | 亚洲国产中文字幕在线视频综合 | 青青草视频破解版 | 久久国产视频网站 | 免费一级国产大片 | 日本高清在线观看天码888 | 欧美精品久久一区二区三区 | 7777奇米影视| 亚洲精品国产福利片 | 亚洲网站在线播放 | 四虎国产精品免费久久久 | 午夜在线播放免费人成无 | 好大好猛好爽好深视频免费 | 成人欧美1314www色视频 | 色婷亚洲 | 精品国产一区二区三区国产馆 | 69人成网站色www | bl双性小说|