mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-03-16 03:42:30 +00:00
Clean up
This commit is contained in:
@@ -85,14 +85,21 @@ public partial class SettingsService
|
||||
|
||||
// Layout: nonce (12 bytes) | paddingLength (1 byte) | tag (16 bytes) | cipher (paddingLength + tokenData.Length)
|
||||
var data = new byte[29 + paddingLength + tokenData.Length];
|
||||
RandomNumberGenerator.Fill(data.AsSpan(0, 12)); // nonce
|
||||
|
||||
// Nonce
|
||||
RandomNumberGenerator.Fill(data.AsSpan(0, 12));
|
||||
|
||||
// Padding length
|
||||
data[12] = (byte)paddingLength;
|
||||
var cipherSource = data.AsSpan(29);
|
||||
RandomNumberGenerator.Fill(cipherSource[..paddingLength]); // random padding
|
||||
tokenData.CopyTo(cipherSource[paddingLength..]); // token
|
||||
|
||||
// Padding
|
||||
RandomNumberGenerator.Fill(data.AsSpan(29, paddingLength));
|
||||
|
||||
// Token data
|
||||
tokenData.CopyTo(data.AsSpan(29 + paddingLength));
|
||||
|
||||
using var aes = new AesGcm(Key.Value, 16);
|
||||
aes.Encrypt(data.AsSpan(0, 12), cipherSource, cipherSource, data.AsSpan(13, 16));
|
||||
aes.Encrypt(data.AsSpan(0, 12), data.AsSpan(29), data.AsSpan(29), data.AsSpan(13, 16));
|
||||
|
||||
writer.WriteStringValue(Prefix + Convert.ToHexStringLower(data));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user