在java中調用sun公司提供的
jce
security/US_export_policy
security/local_policy
ext/sunjce_provider
Java運行時會自動加載這些包
以下是java中調用sun公司提供的
/*字符串 DESede(
import java
import javax
import javax
public class ThreeDes {
private static final String Algorithm =
//keybyte為加密密鑰
//src為被加密的數據緩沖區(源)
public static byte[] encryptMode(byte[] keybyte
try {
//生成密鑰
SecretKey deskey = new SecretKeySpec(keybyte
//加密
Cipher c
c
return c
}
catch (java
e
}
catch (javax
e
}
catch (java
e
}
return null;
}
//keybyte為加密密鑰
//src為加密後的緩沖區
public static byte[] decryptMode(byte[] keybyte
try {
//生成密鑰
SecretKey deskey = new SecretKeySpec(keybyte
//解密
Cipher c
c
return c
}
catch (java
e
}
catch (javax
e
}
catch (java
e
}
return null;
}
//轉換成十六進制字符串
public static String byte
String hs=
String stmp=
for (int n=
stmp=(java
if (stmp
else hs=hs+stmp;
if (n<b
}
return hs
}
public static void main(String[] args){
//添加新安全算法
Security
final byte[] keyBytes = {
(byte)
(byte)
(byte)
}; //
String szSrc =
System
byte[] encoded = encryptMode(keyBytes
System
byte[] srcBytes = decryptMode(keyBytes
System
}
}
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19363.html