Base64 Encoding safe for filenames?(Base64 编码对文件名安全吗?)
问题描述
Base64 编码是否可以安全地用于 Windows 和 Linux 系统上的文件名?根据我的研究,我发现用 - 或 _ 替换结果的所有 / 字符应该可以解决任何问题.
Is Base64 encoding safe to use for filenames on Windows and Linux systems? From my research I have found that replacing all / characters of the result with - or _ should resolve any issues.
谁能提供更多细节?
目前在 Java 中,我正在使用以下代码:
Currently in Java I am using the following peice of code:
MessageDigest md5Digest = MessageDigest.getInstance("MD5");
md5Digest.reset();
md5Digest.update(plainText.getBytes());
byte[] digest = md5Digest.digest();
BASE64Encoder encoder = new BASE64Encoder();
hash = encoder.encode(digest);
hash.replace('/','_');
推荐答案
修改Base64(当/,=和+被替换时)创建名称是安全的,但由于许多文件系统和 url 不区分大小写,因此不能保证反向转换.
Modified Base64 (when /,= and + are replaced) is safe to create names but does not guarantee reverse transformation due to case insensitivity of many file systems and urls.
Base64 区分大小写,因此在不区分大小写的文件系统(所有 Windows 文件系统,忽略 POSIX 子系统情况)的情况下,它不能保证一对一的映射.大多数 url 也不区分大小写,防止一对一映射.
Base64 is case sensitive, so it will not guarantee 1-to-1 mapping in cases of case insensitive file systems (all Windows files systems, ignoring POSIX subsystem cases). Most urls also case insensitive preventing 1-to-1 mapping.
在这种情况下,我会使用 Base32 - 您会得到更长的名称,但 Base32 编码的值对于文件/uri 的使用是 100% 安全的,无需替换任何字符,并且即使在不敏感的情况下也能保证 1 对 1 映射环境(FAT/Win32 NTFS 访问).
I would use Base32 in this case - you'll get names a bit longer, but Base32 encoded values are 100% safe for file/uri usage without replacing any characters and guarantees 1-to-1 mapping even in cases of insensitive environment (FAT/Win32 NTFS access).
不幸的是,框架中通常没有对这种编码的内置支持.另一方面,代码相对简单,可以自己编写或在线查找.
Unfortunately there is usually no built-in support for this encoding in frameworks. On other hand code is relatively simple to write yourself or find online.
http://en.wikipedia.org/wiki/Base32.
这篇关于Base64 编码对文件名安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Base64 编码对文件名安全吗?
基础教程推荐
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
- Java ECDSAwithSHA256 签名长度不一致 2022-01-01
- 将 Windows 证书导入 Java 2022-01-01
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
- 在springboot中如何给mybatis加拦截器 2023-04-29
- 将 double 转换为 Int,向下舍入 2022-01-01
- JPA惰性列表上的流 2022-01-01
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
- Maven:无效的目标版本:10 2022-01-01
