Files
ShellCrash/scripts/libs/gen_base64.sh
2025-12-25 21:07:21 +08:00

26 lines
694 B
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#生成指定位数的加密秘钥符合ss2022协议
gen_random() {
if ckcmd openssl;then
openssl rand --base64 "$1"
elif ckcmd base64;then
head -c "$1" /dev/urandom | base64 | tr -d '\n'
elif busybox base64 --help >/dev/null 2>&1;then
head -c "$1" /dev/urandom | base64 | tr -d '\n'
elif ckcmd uuencode;then
head -c "$1" /dev/urandom | uuencode -m - | sed -n '2p'
else
return 1
fi
}
#对指定字符串进行base64转码
gen_base64() {
if ckcmd base64;then
echo -n "$1" | base64 | tr -d '\n'
elif busybox base64 --help >/dev/null 2>&1;then
echo -n "$1" | busybox base64 | tr -d '\n'
elif ckcmd openssl;then
echo -n "$1" | openssl base64 -A
else
return 1
fi
}