当前位置:网站首页>JS Base64 encoding and decoding
JS Base64 encoding and decoding
2022-07-26 03:41:00 【Learn programming notes】
Base64 It's a way of encoding , Any character can be ( Including binary character stream ) Convert to printable characters .
JavaScript
Defines two and Base64 Related global methods .
- btoa(): String or binary value to Base64 code .
- atob(): hold Base64 The encoding is changed to the original character .
Base64 Methods cannot operate on non ASCII character .
Example
To make a non ASCII Code character to Base64 code , You must use the method described in the previous section to Unicode Double byte string is converted to ASCII Character representation , Then use these two methods .
encodeURIComponent and decodeURIComponent Non essential . Only in URI Only when transferring parameters .
That is to say :btoa and atob You can directly receive a string parameter .
function b64Encode (str) {
return btoa(encodeURIComponent(str));
}
function b64Decode (str) {
return decodeURIComponent(atob(str));
}
var b = b64Encode('JavaScript From entry to mastery ');
var a = b64Decode(b);
console.log(b); // return SmF2YVNjcmlwdCVFNCVCQiU4RSVFNSU4NSVBNFOSU5NyVBOCVFNSU4OCVCMCVFNyVCMiVCRSVFOSU4MCU5QQ==
console.log(a); // return “JavaScript From entry to mastery ”
边栏推荐
- 2020 AF-RCNN: An anchor-free convolutional neural network for multi-categoriesagricultural pest det
- How to choose sentinel vs hystrix?
- 78. Subset
- Moco V2: further upgrade of Moco series
- c语言指针基本知识要点总结(一)
- Why did Mr. Cao, a productionist in the field of high-end tea, choose Ruifeng L6 max?
- DDD落地的那叫一个高级
- Course notes of single chip microcomputer principle and interface technology for migrant workers majoring in electronic information engineering
- MPLS basic experiment configuration
- Dtcloud the next day
猜你喜欢

LoRa和NB-IOT可用用在哪些地方

Hcip day 14

PHP连接mysql数据库,数据库连接静态工具类,简化连接。

C语言函数(2)

Uncaught TypeError: $(...). Onmousenter is not a function JS error, solution:

Alibaba Sentinel - 集群流量控制

Where can Lora and nb-iot be used

easyExcel设置行隐藏,解决setHidden(true)失效问题

How to choose sentinel vs hystrix?

Offline data warehouse from 0 to 1 - phase I resource purchase configuration
随机推荐
基于Caffe ResNet-50网络实现图片分类(仅推理)的实验复现
Network model and protocol
中国数据库 OceanBase 入选 Forrester Translytical 数据平台报告
Leetcode-169. most elements
tf.truncated_ Normal() usage
[virtualization] view the log files of vCenter and esxi hosts
Hcip day 8 notes sorting (OSPF routing control, Appendix E, anti ring, shortest path calculation, republication))
A 4W word redis interview tutorial
三种解决:在点击用户退出登录时,再按浏览器的后退按钮,仍然能够看到之前登录的页面。
How to choose sentinel vs hystrix?
Multi merchant mall system function disassembly lecture 15 - platform side member label
IDEA2020.3.1不能打开(双击不能打开),但可以通过idea.bat打开。
QT notes - temporary floating window
B2B2C多商户系统功能丰富,极易二开
Completion report of communication software development and Application
div设置高度不生效
Performance comparison of ext4, NTFS, XFS, Btrfs, ZFS, f2fs and ReiserFS
C language preprocessing instructions and makefile script explanation
day03_ 1_ Idea tutorial
6-40v input fixed 5V 3.3V output 1.1a current 23-5 package