gpt4 book ai didi

java使用Base64编码实例

转载 作者:qq735679552 更新时间:2022-09-28 22:32:09 31 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章java使用Base64编码实例由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

本文实例为大家分享了java使用base64编码的具体代码,供大家参考,具体内容如下 。

test base64 。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.weiwen.provider.utils;
import java.io.ioexception;
 
import com.alibaba.fastjson.json;
import lombok.extern.slf4j.slf4j;
import org.junit.test;
 
import sun.misc.base64encoder;
import sun.misc.base64decoder;
@slf4j
public class base64 {
 
   @test
   public void testbase64() throws ioexception {
    // base64编码
    string s = "1f2bc1970a2eb19aabc0f94acea922717a1ae998603ff0593baff" ;
    base64encoder encoder = new base64encoder();
    s = encoder.encode(s.getbytes( "utf-8" ));
//   system.out.println(s);
    log.info( "base64编码为:{}" , json.tojsonstring(s));
 
    // base64解码
    base64decoder decoder = new base64decoder();
    byte [] bytes = decoder.decodebuffer(s);
//   system.out.println(new string(bytes, "utf-8"));
    log.info( "base64解码为:{}" , json.tojsonstring( new string(bytes, "utf-8" )));
   }
  }

base64工具类 。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.weiwen.provider.utils;
import java.io.ioexception;
 
import com.alibaba.fastjson.json;
import lombok.extern.slf4j.slf4j;
import org.junit.test;
 
import sun.misc.base64encoder;
import sun.misc.base64decoder;
@slf4j
public class base64 {
 
 
  /**
   * base64 编码
   * @param encodetext
   * @return
   * @throws ioexception
   */
  public static string base64encode(string encodetext) throws ioexception{
   base64encoder encoder = new base64encoder();
   string str = encoder.encode(encodetext.getbytes( "utf-8" ));
   log.info( "base64编码为:{}" , json.tojsonstring(str));
   return str;
  }
 
 
  /**
   * base64 解码
   * @param decodetext
   * @return
   * @throws ioexception
   */
  public static byte [] base64decode(string decodetext) throws ioexception{
    base64decoder decoder = new base64decoder();
    byte [] bytes = decoder.decodebuffer(decodetext);
    log.info( "base64解码为:{}" , json.tojsonstring( new string(bytes, "utf-8" )));
    return bytes;
  }
 
}

以上所述是小编给大家介绍的java使用base64编码详解整合,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对我网站的支持! 。

原文链接:https://blog.csdn.net/weixin_42740530/article/details/88249641 。

最后此篇关于java使用Base64编码实例的文章就讲到这里了,如果你想了解更多关于java使用Base64编码实例的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com