Унификация кодирования chacha_key_plain теперь он в hex, а не в utf8 с потерей данных

This commit is contained in:
RoyceDa
2026-03-28 17:52:13 +02:00
parent f5bfa153b6
commit 61e83bdd43
8 changed files with 23 additions and 23 deletions

View File

@@ -221,7 +221,7 @@ export function DialogProvider(props: DialogProviderProps) {
* Если это сообщение от нас, то проверяем, есть ли внутри chacha_key
*/
try{
decryptKey = Buffer.from(await decodeWithPassword(privatePlain, message.chacha_key), 'binary').toString('utf-8');
decryptKey = Buffer.from(await decodeWithPassword(privatePlain, message.chacha_key), 'binary').toString('hex');
}catch(e) {
decryptKey = "";
}
@@ -232,7 +232,7 @@ export function DialogProvider(props: DialogProviderProps) {
* сообщение пришло нам в результате синхронизации и его нужно расшифровать, если chacha_key нет,
* значит сообщение отправлено с нашего устройства, и зашифровано на стороне отправки (plain_message)
*/
decryptKey = Buffer.from(await decodeWithPassword(privatePlain, message.chacha_key.replace("sync:", "")), 'binary').toString('utf-8');
decryptKey = Buffer.from(await decodeWithPassword(privatePlain, message.chacha_key.replace("sync:", "")), 'binary').toString('hex');
}
if(hasGroup(props.dialog)){
/**
@@ -245,7 +245,7 @@ export function DialogProvider(props: DialogProviderProps) {
* Если сообщение не от меня и не групповое,
* расшифровываем ключ чачи своим приватным ключом
*/
decryptKey = Buffer.from(await decrypt(message.chacha_key, privatePlain), "binary").toString('utf-8');
decryptKey = Buffer.from(await decrypt(message.chacha_key, privatePlain), "binary").toString('hex');
}
finalMessages.push({
from_public_key: message.from_public_key,
@@ -482,7 +482,7 @@ export function DialogProvider(props: DialogProviderProps) {
const attachment = packet.getAttachments()[i];
attachments.push({
...attachment,
blob: attachment.type == AttachmentType.MESSAGES ? await decodeWithPassword(chachaDecryptedKey.toString('utf-8'), attachment.blob) : ""
blob: attachment.type == AttachmentType.MESSAGES ? await decodeWithPassword(chachaDecryptedKey.toString('hex'), attachment.blob) : ""
});
}
@@ -492,7 +492,7 @@ export function DialogProvider(props: DialogProviderProps) {
content: content,
timestamp: timestamp,
readed: 0, //сообщение прочитано
chacha_key: chachaDecryptedKey.toString('utf-8'),
chacha_key: chachaDecryptedKey.toString('hex'),
from_me: 1, //сообщение от нас
plain_message: (decryptedContent as string),
delivered: DeliveredMessageState.DELIVERED,
@@ -636,7 +636,7 @@ export function DialogProvider(props: DialogProviderProps) {
const attachment = packet.getAttachments()[i];
attachments.push({
...attachment,
blob: attachment.type == AttachmentType.MESSAGES ? await decodeWithPassword(chachaDecryptedKey.toString('utf-8'), attachment.blob) : ""
blob: attachment.type == AttachmentType.MESSAGES ? await decodeWithPassword(chachaDecryptedKey.toString('hex'), attachment.blob) : ""
});
}
console.info(attachments);
@@ -646,7 +646,7 @@ export function DialogProvider(props: DialogProviderProps) {
content: content,
timestamp: timestamp,
readed: idle ? 0 : 1,
chacha_key: chachaDecryptedKey.toString('utf-8'),
chacha_key: chachaDecryptedKey.toString('hex'),
from_me: fromPublicKey == publicKey ? 1 : 0,
plain_message: (decryptedContent as string),
delivered: DeliveredMessageState.DELIVERED,
@@ -798,7 +798,7 @@ export function DialogProvider(props: DialogProviderProps) {
* Если сообщение не от меня и не групповое,
* расшифровываем ключ чачи своим приватным ключом
*/
decryptKey = Buffer.from(await decrypt(message.chacha_key, privatePlain), "binary").toString('utf-8');
decryptKey = Buffer.from(await decrypt(message.chacha_key, privatePlain), "binary").toString('hex');
}
finalMessages.push({
from_public_key: message.from_public_key,
@@ -883,7 +883,7 @@ export function DialogProvider(props: DialogProviderProps) {
* Если сообщение не от меня и не групповое,
* расшифровываем ключ чачи своим приватным ключом
*/
decryptKey = Buffer.from(await decrypt(message.chacha_key, privatePlain), "binary").toString('utf-8');
decryptKey = Buffer.from(await decrypt(message.chacha_key, privatePlain), "binary").toString('hex');
}
finalMessages.push({
from_public_key: message.from_public_key,