📄 threedesutil.java
字号:
package cn.js.fan.security;import java.security.*;import javax.crypto.*;import javax.crypto.spec.SecretKeySpec;public class ThreeDesUtil { private static final String Algorithm = "DESede"; public ThreeDesUtil() { Security.addProvider(new com.sun.crypto.provider.SunJCE()); } public static String encrypt2hex(String key, String content) { byte[] r = encryptMode(key.getBytes(), content.getBytes()); return SecurityUtil.byte2hex(r); } public static String decrypthexstr(String key, String hexStr) { byte[] r = decryptMode(key.getBytes(), SecurityUtil.hexstr2byte(hexStr)); if (r!=null) return new String(r); else return ""; } public static byte[] encryptMode(byte[] keybyte, byte[] src) { try { SecretKey deskey = new SecretKeySpec(keybyte, Algorithm); Cipher c1 = Cipher.getInstance(Algorithm); c1.init(Cipher.ENCRYPT_MODE, deskey); return c1.doFinal(src); } catch (java.security.NoSuchAlgorithmException e1) { e1.printStackTrace(); } catch (javax.crypto.NoSuchPaddingException e2) { e2.printStackTrace(); } catch (java.lang.Exception e3) { e3.printStackTrace(); } return null; } public static byte[] decryptMode(byte[] keybyte, byte[] src) { try { SecretKey deskey = new SecretKeySpec(keybyte, Algorithm); Cipher c1 = Cipher.getInstance(Algorithm); c1.init(Cipher.DECRYPT_MODE, deskey); return c1.doFinal(src); } catch (java.security.NoSuchAlgorithmException e1) { e1.printStackTrace(); } catch (javax.crypto.NoSuchPaddingException e2) { e2.printStackTrace(); } catch (java.lang.Exception e3) { e3.printStackTrace(); } return null; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -