Base64
新代码优先使用 UTF-8 或 Base64URL API:
ts
import { decodeBase64, encodeBase64, encodeBase64Url } from "@fast-china/utils";
const encoded = encodeBase64('{"name":"Fast 工具库"}');
const decoded = decodeBase64(encoded);
decoded;
decoded.parseJson<{ name: string }>();
encodeBase64Url("path/参数");encodeSecureBase64 / decodeSecureBase64 使用自定义字典与前缀执行可逆文本混淆,不是加密。通用文本传输使用上面的 UTF-8 Base64 或 Base64URL 方法;这些编码和混淆方法都不能保护密码、Token 等敏感数据。
从 2.1.12 起,随机整数通过商和减法计算余数,保留随机源、拒绝采样和半开区间语义。SecureBase64 默认仍使用 6 位字母前缀和原有固定字典;随机索引异常时编码器抛出 Error,不返回缺失字符的载荷。使用 Base64 Codec 的 Local.set / Session.set 会在写入前抛出 TypeError,并通过 cause 保留编码错误,已有缓存不被覆盖。
升级不会自动修复此前已缺失前缀字符的缓存。应用需校验恢复后的值,再按原格式重新编码写入,或定向处理无法恢复的条目。安装标识应优先恢复并校验,避免无意更换身份;不要把公共解码器改为默认 5 位前缀或自动尝试不同前缀长度。
