A pseudocode example is as follows:
backend encoding
import org.apache.commons.codec.binary.Base64;
String content_base64 = Base64.encodeBase64String(contentsz);//Don't use Base64.encodeBase64URLSafeString(contentsz), it will kill me
Front-end decoding
<script src="${pageContext.request.contextPath}/static/info/common/js/Base64.js" type="text/javascript" charset="utf-8"></script> -- need to import js file, remember.
var base = new Base64 ();
var result = base.decode(column_value);
Precautions:
If the content before encoding is inconsistent with the content after decoding,
solution:
1. First compare the content of the back-end coding and the front-end coding, and then deal with the problem.
Front-end, simple example of encryption and decryption:
//1. Encryption
var str = '124 Chinese content';
var base = new Base64 ();
var result = base.encode(str);
console.log("column_value:" + result);
//2. Decryption
var result2 = base.decode(result);
console.log("column_value:" + result2);
Backend, simple example of encryption and decryption:
//1, encryption
String content=form_column_value_i;
content=content.replaceAll("'", "");//此场景下输出的字符串是带有双引号的'',所以需要处理
byte contentsz[] = content.getBytes();
String content_base64 = Base64.encodeBase64String(contentsz);
System.out.println(content_base64);
//2、解密
String content_base64_string=form_column_name_value;
byte contentsz[] = Base64.decodeBase64(content_base64_string);
String content_base64 = new String(contentsz,"utf-8");
System.out.println(content_base64);