当前位置:   article > 正文

BASE64Encoder_base64encoder.encode(

base64encoder.encode(

在项目过程中,用到对某段字符串进行BASE64加密,然后百度了下,找到解决方案,并记录下来,加深印象。

使用到的jar包:import sun.misc.BASE64Decoder; 

// 将 s 进行 BASE64 编码 
public static String getBASE64(String s) { 
  if (s == null) 
      return null; 
  return (new sun.misc.BASE64Encoder()).encode( s.getBytes() ); 



// 将 BASE64 编码的字符串 s 进行解码 
public static String getFromBASE64(String s) { 
if (s == null) return null; 
BASE64Decoder decoder = new BASE64Decoder(); 
try { 
byte[] b = decoder.decodeBuffer(s); 
return new String(b); 
} catch (Exception e) { 
return null; 

}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/人工智能uu/article/detail/881730
推荐阅读
相关标签
  

闽ICP备14008679号