Java Code Examples for cn.hutool.core.codec.Base64#encode()
The following examples show how to use
cn.hutool.core.codec.Base64#encode() .
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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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); }