1.å¦ä½ç¨Javaè¿è¡3DESå å¯è§£
2.3des java (3key模式)
3.Java 接口数据加密和解密
4.java è¿è¡3DES å å¯è§£å¯
å¦ä½ç¨Javaè¿è¡3DESå å¯è§£
æè¿ä¸ä¸ªåä½åæåºä½¿ç¨3DES交æ¢æ°æ®ï¼æ¬æ¥æç°æç代ç ï¼å¯æåªæ.netçæ¬ï¼æå¡å¨é½æ¯Linuxï¼èä¸åºç¨é½æ¯Javaãäºæ¯å¯¹ç §æä¾ç代ç æ¹äºä¸ä¸ªJavaççæ¬åºæ¥ï¼ä¸»è¦æ¯ä¸çæ3DESï¼æè ¾äºä¸å¤©ï¼ç»äºæå®ã
æè°3DESï¼å°±æ¯æDESåä¸æ¬¡ï¼å½ç¶ä¸æ¯ç®åå°DES DES DESå°±è¡äºï¼ä¸éæäºç¹å®çæåã
å¨ç½ä¸æç´¢äºä¸ä¸3DESï¼æ¾å°å¾å°èµæãæ¾å°GNU CryptoåBouncy Castle两个Javaæ©å å ï¼éé¢åºè¯¥æ3DESçå®ç°å§ã
ä»GNU Cryptoå ¥æï¼æ¾å°ä¸ä¸ªTripleDESçå®ç°ç±»ï¼åç°åæ¥3DESè¿æä¸ä¸ªååå«DESedeï¼å¨ç½ä¸æç´¢TripleDESåDESedeï¼åµåµï¼ç»äºåç°æ´å¤çèµæäºã
Javaçå®å ¨APIå§ç»é£ä¹é¾ç¨ï¼å å建ä¸ä¸ªcipherççç®æ³å¨ä¸å¨å§
Cipher cipher = Cipher.getInstance("DESede");
å¦æ没ææå¼å¸¸çè¯ï¼å°±è¯æè¿ä¸ªç®æ³æ¯ææç
çªç¶æ³ççJDKæ没æå ç½®DESedeï¼äºæ¯æå¼Cryptoï¼ç´æ¥æµè¯ï¼åç°å¯ä»¥æ£ç¡®è¿è¡ãå¨jce.jaréé¢æ¾å°ç¸å ³çç±»ï¼JDKå ç½®äºã
äºæ¯ç´æ¥ç¨DESç代ç æ¥æ¹&æµè¯ï¼æå代ç åæè¿æ ·
SecureRandom sr = new SecureRandom();
DESedeKeySpec dks = new DESedeKeySpec(PASSWORD_CRYPT_KEY.getBytes());
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede");
SecretKey securekey = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance("DESede");
cipher.init(Cipher.ENCRYPT_MODE,开盘量比源码 securekey, sr);
return new String(Hex.encodeHex(cipher.doFinal(str.getBytes())));
éè¦çæçæ¯ï¼è¦ä½¿ç¨DESedeçSpecãFactoryåCipheræè¡
äºæ è¿æ²¡å®ç»ï¼åä½åç»è¿æ¥çé¤äºå¯é¥ä¹å¤ï¼è¿æä¸ä¸ªIVåéãæç´¢äºä¸ä¸ï¼åç°æä¸ä¸ªIvParameterSpecç±»ï¼äºæ¯ä»£ç åæè¿æ ·
SecureRandom sr = new SecureRandom();
DESedeKeySpec dks = new DESedeKeySpec(PASSWORD_CRYPT_KEY.getBytes());
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede");
SecretKey securekey = keyFactory.generateSecret(dks);
IvParameterSpec iv = new IvParameterSpec(PASSWORD_IV.getBytes());
Cipher cipher = Cipher.getInstance("DESede");
cipher.init(Cipher.ENCRYPT_MODE, securekey, iv, sr);
return new String(Hex.encodeHex(cipher.doFinal(str.getBytes())));
ä½æ¯ï¼è¿è¡æ¥éäº
java.security.InvalidAlgorithmParameterException: ECB mode cannot use IV
ECBæ¯ä»ä¹å¢ï¼ä»£ç å®å ¨æ²¡æåECBä»ä¹ç
åä¸ç½æç´¢ï¼ç»ææDESçæ¥é¾å»èé½ææ¸ æ¥äº
blogs.com/lianghuilin/archive////3des.html