diff --git a/native/cpp/CommonCpp/CryptoTools/Tools.h b/native/cpp/CommonCpp/CryptoTools/Tools.h --- a/native/cpp/CommonCpp/CryptoTools/Tools.h +++ b/native/cpp/CommonCpp/CryptoTools/Tools.h @@ -36,6 +36,7 @@ public: static std::string generateRandomString(size_t size); static std::string generateRandomHexString(size_t size); + static std::string generateRandomURLSafeString(size_t size); }; } // namespace crypto diff --git a/native/cpp/CommonCpp/CryptoTools/Tools.cpp b/native/cpp/CommonCpp/CryptoTools/Tools.cpp --- a/native/cpp/CommonCpp/CryptoTools/Tools.cpp +++ b/native/cpp/CommonCpp/CryptoTools/Tools.cpp @@ -29,5 +29,11 @@ return Tools::generateRandomString(size, hexSigns); } +std::string Tools::generateRandomURLSafeString(size_t size) { + static std::string urlSafeSigns = + "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"; + return Tools::generateRandomString(size, urlSafeSigns); +} + } // namespace crypto } // namespace comm diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp --- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp +++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp @@ -2502,7 +2502,7 @@ std::string backupID; try { - backupID = crypto::Tools::generateRandomString(32); + backupID = crypto::Tools::generateRandomURLSafeString(32); } catch (const std::exception &e) { error = "Failed to generate backupID"; }