🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# 组件源码 ``` /** * @category DES解密 * @param instr * 入参|加密字符串|{@link java.lang.String} * @param key * 入参|加密密钥|{@link java.lang.String} * @param decstr * 出参|解密后的字符串|{@link java.lang.String} * @return -1 异常<br/> * 1 成功<br/> */ @InParams(param = { @Param(name = "instr", comment = "加密字符串", type = java.lang.String.class), @Param(name = "key", comment = "加密密钥", type = java.lang.String.class) }) @OutParams(param = { @Param(name = "decstr", comment = "解密后的字符串", type = java.lang.String.class) }) @Returns(returns = { @Return(id = "-1", desp = "异常"), @Return(id = "1", desp = "成功") }) @Component(label = "DES解密", style = "判断型", type = "同步组件", version = "1.0.0", deprecated = false, author = "test", date = "2018-01-19 05:08:46") public static ResultBase P_desDec(String instr, String key) { String strErr = ""; try { key += " "; // DES算法要求有一个可信任的随机数源 SecureRandom random = new SecureRandom(); // 创建一个DESKeySpec对象 DESKeySpec desKey = new DESKeySpec(key.getBytes()); // 创建一个密匙工厂 SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); // 将DESKeySpec对象转换成SecretKey对象 SecretKey securekey = keyFactory.generateSecret(desKey); // Cipher对象实际完成解密操作 Cipher cipher = Cipher.getInstance("DES"); // 用密匙初始化Cipher对象 cipher.init(Cipher.DECRYPT_MODE, securekey, random); // EBCD解码 byte[] by = new byte[instr.length() / 2]; for (int i = 0; i < instr.length(); i += 2) by[i / 2] = (byte) Integer.parseInt(instr.substring(i, i + 2), 16); // 真正开始解密操作 return ResultBase.newSuccessResult(new String(cipher.doFinal(by))); } catch (Exception ex) { AppLog.error(ex); strErr = AppLog.errorMsg(ex); } return ResultBase.newExceptionResult("TPTS0002", "DES解密出现异常:" + strErr); } ``` # 交易中组件使用方式 ![](https://img.kancloud.cn/f0/9d/f09d567754fa61e0a0a7095b53c01a67_1869x892.png) # 参数说明及示例 ## 入口参数 加密字符串:加密过得字符串,示例: `"3df9e122021e353d"` 加密密钥:对待加密字符串加密的密钥,示例: `"123"` ## 出口参数 解密后的字符串:经过解密后的字符串,示例: `__INNER__["result"]`