//des3加密private static final String Algorithm = "DESede"; // 定义 加密算法,可用private static byte[] encryptMode(byte[] key, byte[] src) {try {// 生成密钥SecretKey deskey = new SecretKeySpec(key, 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 (Exception e3) {e3.printStackTrace();}return null;}
/*** 解密des3** @param keybyte 加密密钥,长度为24字节* @param src加密后的缓冲区* @return* @date -2-24*/private 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) {return null;} catch (Exception e3) {return null;}return null;}
//crc加密private static int CRC_XModem(byte[] bytes) {int crc = 0x00;int polynomial = 0x1021;for (int index = 0; index < bytes.length; index++) {byte b = bytes[index];for (int i = 0; i < 8; i++) {boolean bit = ((b >> (7 - i) & 1) == 1);boolean c15 = ((crc >> 15 & 1) == 1);crc <<= 1;if (c15 ^ bit) {crc ^= polynomial;}}}crc &= 0xffff;return crc;}
/*** crc 解密* @param bytes* @return*/private static int CRC_XModem(byte[] bytes) {int crc = 0x00;int polynomial = 0x1021;for (int index = 0; index < bytes.length; index++) {byte b = bytes[index];for (int i = 0; i < 8; i++) {boolean bit = ((b >> (7 - i) & 1) == 1);boolean c15 = ((crc >> 15 & 1) == 1);crc <<= 1;if (c15 ^ bit) {crc ^= polynomial;}}}crc &= 0xffff;return crc;}
如果觉得《java des3加密解密算法 crc加解密》对你有帮助,请点赞、收藏,并留下你的观点哦!