| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.sandu.ximon.admin.utils; |
| | | |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.util.SupplementUtils; |
| | | import org.apache.commons.codec.binary.Base64; |
| | | |
| | | public class Base64Util { |
| | | |
| | | /** |
| | | * å°äºè¿å¶æ°æ®ç¼ç 为BASE64å符串 |
| | | * @param binaryData |
| | | * @return |
| | | */ |
| | | public static String encode(byte[] binaryData) { |
| | | try { |
| | | return new String(Base64.encodeBase64(binaryData)); |
| | | } catch (Exception e) { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å°BASE64å符串æ¢å¤ä¸ºäºè¿å¶æ°æ® |
| | | * @param base64String |
| | | * @return |
| | | */ |
| | | public static byte[] decode(String base64String) { |
| | | try { |
| | | return Base64.decodeBase64(base64String.getBytes()); |
| | | } catch (Exception e) { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | // public static void main(String[] args) { |
| | | // byte[] bytes = "/qUBAAv+AQAD//8yjUBF9xgeI0U=".getBytes(); |
| | | // byte[] bytes1 = Base64.decodeBase64(bytes); |
| | | // System.out.println(SupplementUtils.bytesToHexString(bytes1)); |
| | | // } |
| | | |
| | | |
| | | public static String toBase64Frame (String hexStr) { |
| | | // BigInteger bigInteger = new BigInteger(hexStr, 16); // æ¤æ¹å¼ä¼äº§ç头é¨å¤åºç©ºçä¸åè |
| | | // byte[] bytes = bigInteger.toByteArray(); |
| | | // System.out.println("origin:"+hexStr); |
| | | byte[] bytes = SupplementUtils.hexStringToBytes(hexStr); |
| | | String base64 = encode(bytes); |
| | | return base64; |
| | | } |
| | | } |