Base 64在客户端Javascript中的编码和解码JavaScript中是否有任何方法可用于使用base 64编码对字符串进行编码和解码?
3 回答
倚天杖
TA贡献1828条经验 获得超3个赞
慕少森
TA贡献2019条经验 获得超9个赞
Internet Explorer 10+
// Define the stringvar string = 'Hello World!';// Encode the Stringvar encodedString = btoa(string);console.log(encodedString); // Outputs: "SGVsbG8gV29ybGQh"// Decode the Stringvar decodedString = atob(encodedString);console.log(decodedString); // Outputs: "Hello World!"
跨浏览器
使用Node.js
//Buffer() requires a number, array or string as the first parameter, and an optional encoding type as the second parameter. // Default is utf8, possible encoding types are ascii, utf8, ucs2, base64, binary, and hexvar b = new Buffer('JavaScript');// If we don't use toString(), JavaScript assumes we want to convert the object to utf8.// We can make it convert to other formats by passing the encoding type to toString().var s = b.toString('base64');
var b = new Buffer('SmF2YVNjcmlwdA==', 'base64')var s = b.toString();
使用Dojo.js
var str = dojox.encoding.base64.encode(myByteArray);
var bytes = dojox.encoding.base64.decode(str)
波尔安装角-底座64
<script src="bower_components/angular-base64/angular-base64.js"></script>angular .module('myApp', ['base64']) .controller('myController', [ '$base64', '$scope', function($base64, $scope) { $scope.encoded = $base64.encode('a string'); $scope.decoded = $base64.decode('YSBzdHJpbmc='); }]);
但怎么做?
添加回答
举报
0/150
提交
取消