?? des_encoding.java
字號:
package com.mvc.login;
import java.security.*;
import javax.crypto.*;
public class DES_Encoding {
private byte[] cipherByte;
public String run(String s){ //添加新安全算法
Security.addProvider(new com.sun.crypto.provider.SunJCE());
String Algorithm="DES";
String myinfo=s;
try{
KeyGenerator keygen = KeyGenerator.getInstance(Algorithm); //生成密鑰
SecretKey deskey = keygen.generateKey();
Cipher c1 = Cipher.getInstance(Algorithm); //加密
c1.init(Cipher.ENCRYPT_MODE,deskey);
cipherByte=c1.doFinal(myinfo.getBytes());
}catch(Exception ex){
ex.printStackTrace();
}
return byte2hex(cipherByte);
}
public String byte2hex(byte[] b){ //二進制轉字符串
String hs="";
String stmp="";
for (int n=0;n<b.length;n++){
stmp=(java.lang.Integer.toHexString(b[n] & 0XFF));
if(stmp.length()==1){
hs=hs+"0"+stmp;
}else{
hs=hs+stmp;
}
if(n<b.length-1){
hs=hs+":";
}
if((n!=0)&&(n%16==0)){
hs=hs="<br>";
}
}
return hs.toUpperCase();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -