编码:

#!/bin/bash

# 原始字符串
str='Hello, world!'

# 使用base64编码
encoded_str=$(echo -n $str | base64)

echo $encoded_str

解码:

#!/bin/bash

# base64编码后的字符串
encoded_str='SGVsbG8sIHdvcmxkIQ=='

# 使用base64解码
decoded_str=$(echo -n $encoded_str | base64 -d)

echo $decoded_str

注意:

  • -n选项表示不在字符串末尾添加换行符
  • -d选项表示解码
  • 如果要编码或解码文件,可以使用base64 filename和base64 -d filename命令
Shell 脚本:Base64 编码和解码详解及示例

原文地址: https://www.cveoy.top/t/topic/ojbt 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录