|
14 | 14 | #include <QJsonDocument> |
15 | 15 | #include <QJsonObject> |
16 | 16 | #include <QDBusInterface> |
| 17 | +#include <QString> |
| 18 | +#include <QRandomGenerator> |
| 19 | + |
17 | 20 |
|
18 | 21 | #include <dfm-base/utils/finallyutil.h> |
19 | 22 | #include <dfm-mount/dmount.h> |
@@ -84,12 +87,13 @@ struct crypt_params_reencrypt *resumeParams() |
84 | 87 | static struct crypt_params_reencrypt params |
85 | 88 | { |
86 | 89 | .mode = CRYPT_REENCRYPT_REENCRYPT, |
87 | | - .direction = CRYPT_REENCRYPT_FORWARD, |
88 | | - .resilience = "checksum", |
| 90 | + .direction = CRYPT_REENCRYPT_BACKWARD, |
| 91 | + .resilience = "datashift", |
89 | 92 | .hash = "sha256", |
| 93 | + .data_shift = 32 * 1024, |
90 | 94 | .max_hotzone_size = 0, |
91 | 95 | .device_size = 0, |
92 | | - .flags = CRYPT_REENCRYPT_RESUME_ONLY |
| 96 | + .flags = CRYPT_REENCRYPT_RESUME_ONLY | CRYPT_REENCRYPT_MOVE_FIRST_SEGMENT |
93 | 97 | }; |
94 | 98 | return ¶ms; |
95 | 99 | } |
@@ -148,14 +152,38 @@ bool disk_encrypt_utils::bcValidateParams(const EncryptParams ¶ms) |
148 | 152 | return true; |
149 | 153 | } |
150 | 154 |
|
| 155 | + |
| 156 | +QString disk_encrypt_utils::generateRandomString(int length) |
| 157 | +{ |
| 158 | + // 定义字符集 |
| 159 | + const QString charset = QString("0123456789" |
| 160 | + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 161 | + "abcdefghijklmnopqrstuvwxyz"); |
| 162 | + |
| 163 | + QString result; |
| 164 | + result.reserve(length); |
| 165 | + |
| 166 | + // 获取全局随机生成器实例 |
| 167 | + QRandomGenerator *generator = QRandomGenerator::global(); |
| 168 | + |
| 169 | + // 生成随机字符串 |
| 170 | + for (int i = 0; i < length; ++i) { |
| 171 | + int index = generator->bounded(charset.length()); |
| 172 | + result.append(charset.at(index)); |
| 173 | + } |
| 174 | + |
| 175 | + return result; |
| 176 | +} |
| 177 | + |
151 | 178 | QString disk_encrypt_utils::bcGenRecKey() |
152 | 179 | { |
153 | 180 | QString recKey; |
154 | 181 | QLibrary lib("usec-recoverykey"); |
155 | 182 | dfmbase::FinallyUtil finalClear([&] { if (lib.isLoaded()) lib.unload(); }); |
156 | 183 |
|
157 | 184 | if (!lib.load()) { |
158 | | - qWarning() << "libusec-recoverykey load failed. use uuid as recovery key"; |
| 185 | + qWarning() << "libusec-recoverykey load failed. use default generator"; |
| 186 | + recKey = generateRandomString(); |
159 | 187 | return recKey; |
160 | 188 | } |
161 | 189 |
|
|
0 commit comments