Sometimes it might be required to change rclone crypt
files' names encoding. It is actually very simple and in most cases (server side move or copy is required) can be done without re-uploading any content.
Let's say that this is our crypt configuration:
[.od01_a]
type = onedrive
client_id = redacted
client_secret = redacted
token = redacted
drive_id = redacted
drive_type = personal
[crypt_dir]
type = crypt
remote = .od01_a:enc
password = g5QISjuAebvpNqLzl5vo48ziqWc
password2 = 2N9kHjKF00vARGcve-HwbWgznRg
default names' encoding is using base32 - working everywhere (hence it is default) but with space requirement overhead ≈50%. For example if our not encrypted content is:
$ rclone lsf --recursive --files-only crypt_dir:
directory1/test_file1.txt
directory2/test_file2_long_name_long_name_long_name.txt
base32
encoded encrypted names will look like this:
$ rclone lsf --recursive --files-only .od01_a:enc
lujfu21r5hqrl1216a355a59o0/61fttomk3psj1base1kr826m9k
ahtaqk73vurfofagsp39iq74sg/hh3e0osrt0h8smlpci6q98kjrfs687c1m9go40k0kokacou0n3hjmk10902fbm55ih92l2d5k944a
55 characters long path requires 104 characters! With remotes like OneDrive where max path limit is only 400 chars it creates very serious limitation.
Thankfully rclone offers other encryption schemes.
Base64 - case sensitive (so not suitable for all remotes) but with less overhead ≈35% than base32
. Ideal for remotes like S3 or GoogleDrive.
Base32768 - requires our remote to provide solid UCS2 support and ideally count 2 bytes characters as one character. Examples are OneDrive or Box.
Now let's change default base32
encoding to base32768
. We need to set up a new crypt remote (crypt_dir_new
) by copying the old one in the config file, renaming it and adding filename_encoding = base32768. Choosing a different destination directory (.od01_a:enc_new
) is a good idea too so the old (.od01_a:enc
) and the new don't overlap.
[.od01_a]
type = onedrive
client_id = redacted
client_secret = redacted
token = redacted
drive_id = redacted
drive_type = personal
[crypt_dir]
type = crypt
remote = .od01_a:enc
password = g5QISjuAebvpNqLzl5vo48ziqWc
password2 = 2N9kHjKF00vARGcve-HwbWgznRg
[crypt_dir_new]
type = crypt
remote = .od01_a:enc_new
password = g5QISjuAebvpNqLzl5vo48ziqWc
password2 = 2N9kHjKF00vARGcve-HwbWgznRg
filename_encoding = base32768
Then we can do a server side move or copy:
$ rclone move crypt_dir crypt_dir_new: --server-side-across-configs
or
$ rclone copy crypt_dir: crypt_dir_new: --server-side-across-configs
And here we are:
$ rclone lsf --recursive --files-only .od01_a:enc_new
縳昢┅涻窂ᙊⰅ伉蛟/㹯鸘胣跳ᡊ頡秈♶䴿
傝冴䊿ꈏ衊槹ⴒ轄食/沃幸駝የ餵诲䆉䣓鑜㽇嚖䱘㙔Ꮨ瞬訠苑甴ᖉڏ唥㲑䪕❅瞄㞿
# unencrypted names of course remain the same
$ rclone lsf --recursive --files-only crypt_dir_new:
directory1/test_file1.txt
directory2/test_file2_long_name_long_name_long_name.txt
55 characters long path does not occupy 104 characters but only 36. Sweet. For ASCII only names we actually end up with shorter path than original.
PS. If not sure whether remote supports base32768
rclone offers automated test:
$ rclone test info --check-length --check-base32768 .od01_a:test
2025/02/13 19:25:54 NOTICE: OneDrive root 'test/rclone-test-info-yidekoj5/test-base32768': 0 differences found
2025/02/13 19:25:54 NOTICE: OneDrive root 'test/rclone-test-info-yidekoj5/test-base32768': 1028 matching files
// .od01_a
maxFileLength = 326 // for 1 byte unicode characters
maxFileLength = 326 // for 2 byte unicode characters
maxFileLength = 326 // for 3 byte unicode characters
maxFileLength = 163 // for 4 byte unicode characters
base32768isOK = true // make sure maxFileLength for 2 byte unicode chars is the same as for 1 byte characters