cn.hutool.core.codec.Base64 Java Examples
The following examples show how to use
cn.hutool.core.codec.Base64.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ITSUtils.java From signature with MIT License | 6 votes |
/** * create by: iizvv * description: 获取Token * create time: 2019-06-29 15:14 * * @return 请求头 */ static Map getToken(String p8, String iss, String kid) { String s = p8. replace("-----BEGIN PRIVATE KEY-----", ""). replace("-----END PRIVATE KEY-----", ""); byte[] encodeKey = Base64.decode(s); String token = null; try { token = Jwts.builder(). setHeaderParam(JwsHeader.ALGORITHM, "ES256"). setHeaderParam(JwsHeader.KEY_ID,kid). setHeaderParam(JwsHeader.TYPE, "JWT"). setIssuer(iss). claim("exp", System.currentTimeMillis()/1000 + 60 * 10). setAudience("appstoreconnect-v1"). signWith(SignatureAlgorithm.ES256, new ECPrivateKeyImpl(encodeKey)). compact(); } catch (InvalidKeyException e) { e.printStackTrace(); } Map map = new HashMap(); map.put("Content-Type", "application/json"); map.put("Authorization", "Bearer " + token); return map; }
Example #2
Source File: AuthUtils.java From smaker with GNU Lesser General Public License v3.0 | 6 votes |
/** * 从header 请求中的clientId/clientsecect * * @param header header中的参数 * @throws RuntimeException if the Basic header is not present or is not valid * Base64 */ public static String[] extractAndDecodeHeader(String header) throws IOException { byte[] base64Token = header.substring(6).getBytes("UTF-8"); byte[] decoded; try { decoded = Base64.decode(base64Token); } catch (IllegalArgumentException e) { throw new RuntimeException( "Failed to decode basic authentication token"); } String token = new String(decoded, CharsetUtil.UTF_8); int delim = token.indexOf(":"); if (delim == -1) { throw new RuntimeException("Invalid basic authentication token"); } return new String[]{token.substring(0, delim), token.substring(delim + 1)}; }
Example #3
Source File: WebUtils.java From smaker with GNU Lesser General Public License v3.0 | 6 votes |
/** * 从request 获取CLIENT_ID * * @return */ @SneakyThrows public static String[] getClientId(ServerHttpRequest request) { String header = request.getHeaders().getFirst(HttpHeaders.AUTHORIZATION); if (header == null || !header.startsWith(BASIC_)) { throw new CheckedException("请求头中client信息为空"); } byte[] base64Token = header.substring(6).getBytes("UTF-8"); byte[] decoded; try { decoded = Base64.decode(base64Token); } catch (IllegalArgumentException e) { throw new CheckedException( "Failed to decode basic authentication token"); } String token = new String(decoded, StandardCharsets.UTF_8); int delim = token.indexOf(":"); if (delim == -1) { throw new CheckedException("Invalid basic authentication token"); } return new String[]{token.substring(0, delim), token.substring(delim + 1)}; }
Example #4
Source File: OcrUtils.java From tools-ocr with GNU Lesser General Public License v3.0 | 6 votes |
private static String bdBaseOcr(byte[] imgData, String type){ String[] urlArr = new String[]{"http://ai.baidu.com/tech/ocr/general", "http://ai.baidu.com/index/seccode?action=show"}; StringBuilder cookie = new StringBuilder(); for (String url : urlArr) { HttpResponse cookieResp = WebUtils.get(url); List<String> ckList = cookieResp.headerList("Set-Cookie"); for (String s : ckList) { cookie.append(s.replaceAll("expires[\\S\\s]+", "")); } } HashMap<String, String> header = new HashMap<>(); header.put("Referer", "http://ai.baidu.com/tech/ocr/general"); header.put("Cookie", cookie.toString()); String data = "type="+URLUtil.encodeQuery(type)+"&detect_direction=false&image_url&image=" + URLUtil.encodeQuery("data:image/jpeg;base64," + Base64.encode(imgData)) + "&language_type=CHN_ENG"; HttpResponse response = WebUtils.postRaw("http://ai.baidu.com/aidemo", data, 0, header); return extractBdResult(WebUtils.getSafeHtml(response)); }
Example #5
Source File: OcrUtils.java From tools-ocr with GNU Lesser General Public License v3.0 | 6 votes |
public static String sogouWebOcr(byte[] imgData) { String url = "https://deepi.sogou.com/api/sogouService"; String referer = "https://deepi.sogou.com/?from=picsearch&tdsourcetag=s_pctim_aiomsg"; String imageData = Base64.encode(imgData); long t = System.currentTimeMillis(); String sign = SecureUtil.md5("sogou_ocr_just_for_deepibasicOpenOcr" + t + imageData.substring(0, Math.min(1024, imageData.length())) + "4b66a37108dab018ace616c4ae07e644"); Map<String, Object> data = new HashMap<>(); data.put("image", imageData); data.put("lang", "zh-Chs"); data.put("pid", "sogou_ocr_just_for_deepi"); data.put("salt", t); data.put("service", "basicOpenOcr"); data.put("sign", sign); HttpRequest request = HttpUtil.createPost(url).timeout(15000); request.form(data); request.header("Referer", referer); HttpResponse response = request.execute(); return extractSogouResult(WebUtils.getSafeHtml(response)); }
Example #6
Source File: RestFileInfoService.java From Guns with GNU Lesser General Public License v3.0 | 6 votes |
/** * 预览当前用户头像 * * @author fengshuonan * @Date 2019-05-04 17:04 */ public byte[] previewAvatar() { //获取当前用户 LoginUser currentUser = LoginContextHolder.getContext().getUser(); if (currentUser == null) { throw new ServiceException(CoreExceptionEnum.NO_CURRENT_USER); } //获取当前用户的头像id RestUser user = restUserService.getById(currentUser.getId()); String avatarFileId = user.getAvatar(); try { //返回头像id的字节流 return getFileBytes(avatarFileId); } catch (Exception e) { //返回默认头像 return Base64.decode(DefaultAvatar.BASE_64_AVATAR); } }
Example #7
Source File: AuthUtil.java From albedo with GNU Lesser General Public License v3.0 | 6 votes |
/** * 从header 请求中的clientId/clientsecect * * @param header header中的参数 */ @SneakyThrows public String[] extractAndDecodeHeader(String header) { byte[] base64Token = header.substring(6).getBytes(StandardCharsets.UTF_8); byte[] decoded; try { decoded = Base64.decode(base64Token); } catch (IllegalArgumentException e) { throw new RuntimeException( "Failed to decode basic authentication token"); } String token = new String(decoded, StandardCharsets.UTF_8); int delim = token.indexOf(":"); if (delim == -1) { throw new RuntimeException("Invalid basic authentication token"); } return new String[]{token.substring(0, delim), token.substring(delim + 1)}; }
Example #8
Source File: AesEncryptUtil.java From jeecg-cloud with Apache License 2.0 | 6 votes |
/** * 解密方法 * @param data 要解密的数据 * @param key 解密key * @param iv 解密iv * @return 解密的结果 * @throws Exception */ public static String desEncrypt(String data, String key, String iv) throws Exception { try { byte[] encrypted1 = Base64.decode(data); Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES"); IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes()); cipher.init(Cipher.DECRYPT_MODE, keyspec, ivspec); byte[] original = cipher.doFinal(encrypted1); String originalString = new String(original); return originalString; } catch (Exception e) { e.printStackTrace(); return null; } }
Example #9
Source File: WebUtil.java From albedo with GNU Lesser General Public License v3.0 | 6 votes |
/** * 从request 获取CLIENT_ID * * @return */ @SneakyThrows public String[] getClientId(ServerHttpRequest request) { String header = request.getHeaders().getFirst(HttpHeaders.AUTHORIZATION); if (header == null || !header.startsWith(CommonConstants.BASIC_)) { throw new CheckedException("请求头中client信息为空"); } byte[] base64Token = header.substring(6).getBytes(StandardCharsets.UTF_8); byte[] decoded; try { decoded = Base64.decode(base64Token); } catch (IllegalArgumentException e) { throw new CheckedException( "Failed to decode basic authentication token"); } String token = new String(decoded, StandardCharsets.UTF_8); int delim = token.indexOf(":"); if (delim == -1) { throw new CheckedException("Invalid basic authentication token"); } return new String[]{token.substring(0, delim), token.substring(delim + 1)}; }
Example #10
Source File: UserController.java From halo with GNU General Public License v3.0 | 6 votes |
@PutMapping("mfa/generate") @ApiOperation("Generate Multi-Factor Auth qr image") @DisableOnCondition public MultiFactorAuthVO generateMFAQrImage(@RequestBody MultiFactorAuthParam multiFactorAuthParam, User user) { if (MFAType.NONE == user.getMfaType()) { if (MFAType.TFA_TOTP == multiFactorAuthParam.getMfaType()) { String mfaKey = TwoFactorAuthUtils.generateTFAKey(); String optAuthUrl = TwoFactorAuthUtils.generateOtpAuthUrl(user.getNickname(), mfaKey); String qrImageBase64 = "data:image/png;base64," + Base64.encode(QrCodeUtil.generatePng(optAuthUrl, 128, 128)); return new MultiFactorAuthVO(qrImageBase64, optAuthUrl, mfaKey, MFAType.TFA_TOTP); } else { throw new BadRequestException("暂不支持的 MFA 认证的方式"); } } else { throw new BadRequestException("MFA 认证已启用,无需重复操作"); } }
Example #11
Source File: MobileTokenLoginSuccessHandler.java From Taroco with Apache License 2.0 | 6 votes |
/** * Decodes the header into a username and password. * * @throws BadCredentialsException if the Basic header is not present or is not valid * Base64 */ private String[] extractAndDecodeHeader(String header) throws IOException { final byte[] base64Token = header.substring(6).getBytes(StandardCharsets.UTF_8); byte[] decoded; try { decoded = Base64.decode(base64Token); } catch (IllegalArgumentException e) { throw new BadCredentialsException("Failed to decode basic authentication token"); } final String token = new String(decoded, StandardCharsets.UTF_8); final int delim = token.indexOf(":"); if (delim == -1) { throw new BadCredentialsException("Invalid basic authentication token"); } return new String[] {token.substring(0, delim), token.substring(delim + 1)}; }
Example #12
Source File: Base64Test.java From albedo with GNU Lesser General Public License v3.0 | 5 votes |
/** * c3dhZ2dlcjpzd2FnZ2Vy * * @throws Exception */ @Test public void decode() throws Exception { String encode = Base64.encode("swagger:swagger"); System.out.println(encode); byte[] base64Token = encode.getBytes(StandardCharsets.UTF_8); byte[] decoded = Base64.decode(base64Token); String token = new String(decoded, StandardCharsets.UTF_8); System.out.println(token); }
Example #13
Source File: OauthServiceImpl.java From plumemo with Apache License 2.0 | 5 votes |
@Override public HttpResult oauthLoginByGithub() { HttpResult httpResult = BeanTool.getBean(ByteBlogsClient.class).githubAuthorize(Base64.encode("scope=helloblog")); log.debug("oauthLoginByGithub {}", httpResult); return httpResult; }
Example #14
Source File: SubHDCommon.java From SubTitleSearcher with Apache License 2.0 | 5 votes |
/** * 下载字幕 * @param url * @return */ public static JSONObject downContent(String url) { String result = HtHttpUtil.http.get(baseUrl+url, HtHttpUtil.http.default_charset, HtHttpUtil.http._ua, baseUrl+url); Document doc = Jsoup.parse(result); Elements matchList = doc.select("#down"); if(matchList.size() == 0)return null; Element down = matchList.get(0); Map<String, Object> postData = new HashMap<String, Object>(); postData.put("sub_id", matchList.attr("sid")); postData.put("dtoken", down.attr("dtoken")); result = HtHttpUtil.http.post(baseUrl+"/ajax/down_ajax", postData); if(result == null || !result.contains("}"))return null; JSONObject resultJson = JSONUtil.parseObj(result); if(resultJson == null || !resultJson.getBool("success"))return null; String downUrl = resultJson.getStr("url"); String filename = StringUtil.basename(downUrl); //HtHttpUtil.http.debug=true; byte[] data = HtHttpUtil.http.getBytes(downUrl, HtHttpUtil.http._ua, baseUrl+url); JSONObject resp = new JSONObject(); resp.put("filename", filename); resp.put("ext", StringUtil.extName(filename).toLowerCase()); resp.put("data", Base64.encode(data)); return resp; }
Example #15
Source File: ZIMuKuCommon.java From SubTitleSearcher with Apache License 2.0 | 5 votes |
/** * 下载字幕 * @param url * @return */ public static JSONObject downContent(String url) { String result = httpGet(baseUrl+url); String downUrl = RegexUtil.getMatchStr(result, "<a\\s+id=\"down1\"\\s+href=\"([^\"]*/dld/[\\w]+\\.html)\"" , Pattern.DOTALL); if(downUrl == null)return null; if(!downUrl.startsWith("http")) { downUrl = baseUrl + downUrl; } result = httpGet(downUrl); if(result == null)return null; //System.out.println(result); JSONArray resList = RegexUtil.getMatchList(result, "<li><a\\s+rel=\"nofollow\"\\s+href=\"([^\"]*/download/[^\"]+)\"", Pattern.DOTALL); if(resList == null || resList.size() == 0 || resList.getJSONArray(0).size() == 0)return null; //HtHttpUtil.http.debug=true; HttpResponse httpResp = HtHttpUtil.http.getResponse(addBaseUrl(resList.getJSONArray(0).getStr(0)), null, downUrl); int i = 0; while(httpResp == null && resList.size() > ++i) { httpResp = HtHttpUtil.http.getResponse(addBaseUrl(resList.getJSONArray(1).getStr(0)), null, downUrl); } //System.out.println(httpResp); if(httpResp == null)return null; String filename = HtHttpUtil.getFileName(httpResp); byte[] data = httpResp.bodyBytes(); //System.out.println(filename); JSONObject resp = new JSONObject(); resp.put("filename", filename); resp.put("ext", StringUtil.extName(filename).toLowerCase()); resp.put("data", Base64.encode(data)); return resp; }
Example #16
Source File: MD5Util.java From scaffold-cloud with MIT License | 5 votes |
public static String encoderByMd5(String str) throws UnsupportedEncodingException { MessageDigest md5; String newstr = ""; try { md5 = MessageDigest.getInstance("MD5"); //加密后的字符串 newstr = Base64.encode(md5.digest(str.getBytes(StandardCharsets.UTF_8))); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return newstr; }
Example #17
Source File: PasswordDecoderFilter.java From albedo with GNU Lesser General Public License v3.0 | 5 votes |
public static String decryptAes(String data, String pass) { AES aes = new AES(Mode.CBC, Padding.NoPadding, new SecretKeySpec(pass.getBytes(), KEY_ALGORITHM), new IvParameterSpec(pass.getBytes())); byte[] result = aes.decrypt(Base64.decode(data.getBytes(StandardCharsets.UTF_8))); return new String(result, StandardCharsets.UTF_8); }
Example #18
Source File: FileInfoService.java From Guns with GNU Lesser General Public License v3.0 | 5 votes |
/** * 预览当前用户头像 * * @author fengshuonan * @Date 2019-05-04 17:04 */ public byte[] previewAvatar() { LoginUser currentUser = LoginContextHolder.getContext().getUser(); if (currentUser == null) { throw new ServiceException(CoreExceptionEnum.NO_CURRENT_USER); } //获取当前用户的头像id User user = userService.getById(currentUser.getId()); String avatar = user.getAvatar(); //如果头像id为空就返回默认的 if (ToolUtil.isEmpty(avatar)) { return Base64.decode(DefaultAvatar.BASE_64_AVATAR); } else { //文件id不为空就查询文件记录 FileInfo fileInfo = this.getById(avatar); if (fileInfo == null) { return Base64.decode(DefaultAvatar.BASE_64_AVATAR); } else { try { String filePath = fileInfo.getFilePath(); return IoUtil.readBytes(new FileInputStream(filePath)); } catch (FileNotFoundException e) { log.error("头像未找到!", e); return Base64.decode(DefaultAvatar.BASE_64_AVATAR); } } } }
Example #19
Source File: FileUtil.java From yshopmall with Apache License 2.0 | 5 votes |
public static String fileToBase64(File file) throws Exception { FileInputStream inputFile = new FileInputStream(file); String base64; byte[] buffer = new byte[(int)file.length()]; inputFile.read(buffer); inputFile.close(); base64=Base64.encode(buffer); return base64.replaceAll("[\\s*\t\n\r]", ""); }
Example #20
Source File: FileUtils.java From sk-admin with Apache License 2.0 | 5 votes |
public static String fileToBase64(File file) throws Exception { FileInputStream inputFile = new FileInputStream(file); String base64; byte[] buffer = new byte[(int)file.length()]; inputFile.read(buffer); inputFile.close(); base64= Base64.encode(buffer); return base64.replaceAll("[\\s*\t\n\r]", ""); }
Example #21
Source File: ShiroConfig.java From kvf-admin with MIT License | 5 votes |
/** * cookie管理对象; * @return cookieRememberMeManager */ private CookieRememberMeManager rememberMeManager() { CookieRememberMeManager cookieRememberMeManager = new CookieRememberMeManager(); cookieRememberMeManager.setCookie(rememberMeCookie()); // rememberMe cookie加密的密钥 建议每个项目都不一样 默认AES算法 密钥长度(128 256 512 位) cookieRememberMeManager.setCipherKey(Base64.decode("2AvVhdsgUs0FSA3SDFAdag==")); return cookieRememberMeManager; }
Example #22
Source File: AesEncryptUtil.java From jeecg-cloud with Apache License 2.0 | 5 votes |
/** * 加密方法 * @param data 要加密的数据 * @param key 加密key * @param iv 加密iv * @return 加密的结果 * @throws Exception */ public static String encrypt(String data, String key, String iv) throws Exception { try { Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");//"算法/模式/补码方式"NoPadding PkcsPadding int blockSize = cipher.getBlockSize(); byte[] dataBytes = data.getBytes(); int plaintextLength = dataBytes.length; if (plaintextLength % blockSize != 0) { plaintextLength = plaintextLength + (blockSize - (plaintextLength % blockSize)); } byte[] plaintext = new byte[plaintextLength]; System.arraycopy(dataBytes, 0, plaintext, 0, dataBytes.length); SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES"); IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes()); cipher.init(Cipher.ENCRYPT_MODE, keyspec, ivspec); byte[] encrypted = cipher.doFinal(plaintext); return Base64.encodeUrlSafe(encrypted); } catch (Exception e) { e.printStackTrace(); return null; } }
Example #23
Source File: SecureCommon.java From yue-library with Apache License 2.0 | 5 votes |
/** * 钉钉机器人签名 * * @param dingtalkRobotWebhook 钉钉机器人Webhook * @param dingtalkRobotSignSecret 钉钉机器人密钥,机器人安全设置页面,加签一栏下面显示的SEC开头的字符串 * @return 钉钉机器人签名后的Webhook */ public static String dingtalkRobotSign(String dingtalkRobotWebhook, String dingtalkRobotSignSecret) { Long timestamp = System.currentTimeMillis(); String signContent = timestamp + "\n" + dingtalkRobotSignSecret; byte[] signByte = SecureUtil.hmac(HmacAlgorithm.HmacSHA256, dingtalkRobotSignSecret).digest(signContent); String sign = URLUtil.encode(Base64.encode(signByte)); return dingtalkRobotWebhook + "×tamp=" + timestamp + "&sign=" + sign; }
Example #24
Source File: ZIMuKuCommon.java From SubTitleSearcher with Apache License 2.0 | 5 votes |
/** * 下载字幕 * @param url * @return */ public static JSONObject downContent(String url) { String result = httpGet(baseUrl+url); String downUrl = RegexUtil.getMatchStr(result, "<a\\s+id=\"down1\"\\s+href=\"([^\"]*/dld/[\\w]+\\.html)\"" , Pattern.DOTALL); if(downUrl == null)return null; if(!downUrl.startsWith("http")) { downUrl = baseUrl + downUrl; } result = httpGet(downUrl); if(result == null)return null; //System.out.println(result); JSONArray resList = RegexUtil.getMatchList(result, "<li><a\\s+rel=\"nofollow\"\\s+href=\"([^\"]*/download/[^\"]+)\"", Pattern.DOTALL); if(resList == null || resList.size() == 0 || resList.getJSONArray(0).size() == 0)return null; //HtHttpUtil.http.debug=true; HttpResponse httpResp = HtHttpUtil.http.getResponse(addBaseUrl(resList.getJSONArray(0).getStr(0)), null, downUrl); int i = 0; while(httpResp == null && resList.size() > ++i) { httpResp = HtHttpUtil.http.getResponse(addBaseUrl(resList.getJSONArray(1).getStr(0)), null, downUrl); } //System.out.println(httpResp); if(httpResp == null)return null; String filename = HtHttpUtil.getFileName(httpResp); byte[] data = httpResp.bodyBytes(); //System.out.println(filename); JSONObject resp = new JSONObject(); resp.put("filename", filename); resp.put("ext", StringUtil.extName(filename).toLowerCase()); resp.put("data", Base64.encode(data)); return resp; }
Example #25
Source File: SubHDCommon.java From SubTitleSearcher with Apache License 2.0 | 5 votes |
/** * 下载字幕 * @param url * @return */ public static JSONObject downContent(String url) { String result = HtHttpUtil.http.get(baseUrl+url, HtHttpUtil.http.default_charset, HtHttpUtil.http._ua, baseUrl+url); Document doc = Jsoup.parse(result); Elements matchList = doc.select("#down"); if(matchList.size() == 0)return null; Element down = matchList.get(0); Map<String, Object> postData = new HashMap<String, Object>(); postData.put("sub_id", matchList.attr("sid")); postData.put("dtoken", down.attr("dtoken")); result = HtHttpUtil.http.post(baseUrl+"/ajax/down_ajax", postData); if(result == null || !result.contains("}"))return null; JSONObject resultJson = JSONUtil.parseObj(result); if(resultJson == null || !resultJson.getBool("success"))return null; String downUrl = resultJson.getStr("url"); String filename = StringUtil.basename(downUrl); //HtHttpUtil.http.debug=true; byte[] data = HtHttpUtil.http.getBytes(downUrl, HtHttpUtil.http._ua, baseUrl+url); JSONObject resp = new JSONObject(); resp.put("filename", filename); resp.put("ext", StringUtil.extName(filename).toLowerCase()); resp.put("data", Base64.encode(data)); return resp; }
Example #26
Source File: DESUtils.java From feiqu-opensource with Apache License 2.0 | 5 votes |
public final String decryptString(String str) { try { byte[] bytes = Base64.decode(str); Cipher cipher = Cipher.getInstance("DES"); cipher.init(Cipher.DECRYPT_MODE, key); bytes = cipher.doFinal(bytes); return new String(bytes); } catch (Exception e) { throw new RuntimeException(e); } }
Example #27
Source File: DESUtils.java From feiqu-opensource with Apache License 2.0 | 5 votes |
public final String encryptString(String str) { byte[] bytes = str.getBytes(); try { Cipher cipher = Cipher.getInstance("DES"); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] encryptStrBytes = cipher.doFinal(bytes); return Base64.encode(encryptStrBytes); } catch (Exception e) { throw new RuntimeException(e); } }
Example #28
Source File: DESUtils.java From feiqu-opensource with Apache License 2.0 | 5 votes |
/** * 设置加密的校验码 */ private void setkey(String keyStr) { try { // L.cm 2015-01-20 将加密的密匙Base64 // fix Caused by: java.security.InvalidKeyException: Wrong key size // String desKey = Base64.encodeBase64String(keyStr.getBytes("UTF-8")); String desKey = Base64.encode(keyStr.getBytes("UTF-8")); DESKeySpec objDesKeySpec = new DESKeySpec(desKey.getBytes("UTF-8")); SecretKeyFactory objKeyFactory = SecretKeyFactory.getInstance("DES"); key = objKeyFactory.generateSecret(objDesKeySpec); } catch (Exception e) { throw new RuntimeException(e); } }
Example #29
Source File: PasswordDecoderFilter.java From smaker with GNU Lesser General Public License v3.0 | 5 votes |
private static String decryptAES(String data, String pass) { AES aes = new AES(Mode.CBC, Padding.NoPadding, new SecretKeySpec(pass.getBytes(), KEY_ALGORITHM), new IvParameterSpec(pass.getBytes())); byte[] result = aes.decrypt(Base64.decode(data.getBytes(StandardCharsets.UTF_8))); return new String(result, StandardCharsets.UTF_8); }
Example #30
Source File: DownZIMu.java From SubTitleSearcher with Apache License 2.0 | 4 votes |
/** * 字幕库 * * @param row * @param filename * @param url * @param charset * @param simplified * @return */ public static boolean downAndSave_ZiMuKu(int index, JSONObject row,JSONObject fileRow, String filename, String url, DownParm downParm) { try { JSONObject zimuContent = ZIMuKuCommon.downContent(url); if (zimuContent == null) return false; String ext = zimuContent.getStr("ext"); byte[] data = Base64.decode(zimuContent.getStr("data")); // *.srt、*.ass、*.ssa、*.zip、*.rar、*.7z if (data == null || data.length < 100) { return false; } logger.info("save=" + filename); if (ext.equals("zip") || ext.equals("rar") || ext.equals("7z")) { new ExtractDialog(MainWin.frame, index, downParm, row.getJSONObject("data").getStr("title"),ext,filename, data).setVisible(true); return true; } else if (ArrayUtil.contains(AppConfig.subExtNames, ext.toLowerCase())) { // Vector<Object> colData = MainWin.getSubTableData(row.getStr("key")); // String charset = (String)colData.get(5); if(downParm.filenameType == DownParm.filenameType_BAT) { filename += (".chn" + (index+1)) + "." + ext; }else { filename += "." + ext; } if (downParm.simplified) { String dataStr = new String(data, downParm.charset); dataStr = ChineseHelper.convertToSimplifiedChinese(dataStr); MyFileUtil.fileWrite(filename, dataStr, "UTF-8", ""); } else { MyFileUtil.fileWriteBin(filename, data); } } else { return false; } return true; } catch (Exception e) { logger.error(e); } return false; }