导出公钥文件接口
@RequiresPermissions('manage:spasymkeyvalue:exportPk') @GetMapping('/exportPk/{id}') public void exportPk(@PathVariable('id') Long id, HttpServletRequest request, HttpServletResponse response) throws IOException { String fixedStr = '3059301306072A8648CE3D020106082A811CCF5501822D03420004';//固定字符 SpAsymKeyValue spAsymKeyValue = spAsymKeyValueService.selectSpAsymKeyValueById(id); String pkValue = spAsymKeyValue.getPkValue(); response.setCharacterEncoding('utf-8'); if(StringUtils.isEmpty(pkValue)){ // response.setStatus(HttpServletResponse.SC_OK); response.getWriter().write('公钥值为空'); return; } String fileName = spAsymKeyValue.getKeyName(); String filePath = FileUtils.getCertFilePath()+fileName+'.extPk'; File pkFile = new File(filePath); if(!pkFile.exists()){ pkFile.createNewFile(); } //取固定字符+公钥值 String ePkValue = fixedStr.concat(pkValue); //ePkValue转base64写入文件 String ePkValueB64str = Base64Utils.encode(ePkValue.getBytes()); FileWriter fileWriter = new FileWriter(pkFile,false); fileWriter.write(ePkValueB64str); fileWriter.close(); response.setContentType('multipart/form-data'); response.setHeader('Content-Disposition', 'attachment;fileName=' + FileUtils.setFileDownloadHeader(request, pkFile.getName())); FileUtils.writeBytes(filePath, response.getOutputStream()); }
function exportPk() { var table = $.table; var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId); window.location.href = prefix + '/exportPk/' + rows.join(); }
原文地址: https://www.cveoy.top/t/topic/bh8s 著作权归作者所有。请勿转载和采集!