Java Code Examples for cn.hutool.core.codec.Base64#decode()
The following examples show how to use
cn.hutool.core.codec.Base64#decode() .
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: 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 2
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 3
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 4
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 5
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 6
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 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: 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 9
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 10
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 11
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 12
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; }
Example 13
Source File: DownZIMu.java From SubTitleSearcher with Apache License 2.0 | 4 votes |
/** * SubHD * * @param row * @param filename * @param url * @param charset * @param simplified * @return */ public static boolean downAndSave_SubHD(int index, JSONObject row, JSONObject fileRow, String filename, String url, DownParm downParm) { try { JSONObject zimuContent = SubHDCommon.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; }
Example 14
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; }
Example 15
Source File: DownZIMu.java From SubTitleSearcher with Apache License 2.0 | 4 votes |
/** * SubHD * * @param row * @param filename * @param url * @param charset * @param simplified * @return */ public static boolean downAndSave_SubHD(int index, JSONObject row, JSONObject fileRow, String filename, String url, DownParm downParm) { try { JSONObject zimuContent = SubHDCommon.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; }