// 使用 CryptoJS 进行 Base64 编码和解码的示例代码
// 引入 CryptoJS 库
// 可以通过 CDN 或 npm 安装来引入
// <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/crypto-js.min.js"></script>
// 示例字符串
var message = "Hello, World!";
// 使用 CryptoJS 进行 Base64 编码
var encodedMessage = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(message));
console.log("Base64 Encoded:", encodedMessage); // 输出编码后的字符串
// 使用 CryptoJS 进行 Base64 解码
var decodedMessage = CryptoJS.enc.Utf8.stringify(CryptoJS.enc.Base64.parse(encodedMessage));
console.log("Base64 Decoded:", decodedMessage); // 输出解码后的字符串
CryptoJS.enc.Base64.stringify
:将 UTF-8 字符串转换为 Base64 编码的字符串。CryptoJS.enc.Utf8.parse
:将字符串解析为 UTF-8 格式的字节数组。CryptoJS.enc.Utf8.stringify
:将 Base64 编码的字符串转换回 UTF-8 字符串。CryptoJS.enc.Base64.parse
:将 Base64 编码的字符串解析为字节数组。通过以上步骤,你可以轻松地使用 CryptoJS 库对字符串进行 Base64 编码和解码。
上一篇:js base64解码
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站