MCPcopy Create free account
hub / github.com/Selectively11/CloudRedirect / GetDecryptedPayload

Method GetDecryptedPayload

ui/Services/Patching/Patcher.cs:108–146  ·  view source on GitHub ↗
(string cachePath)

Source from the content-addressed store, hash-verified

106 }
107
108 byte[] GetDecryptedPayload(string cachePath)
109 {
110 var info = new FileInfo(cachePath);
111 if (!info.Exists) return null;
112
113 long size = info.Length;
114 var lastWrite = info.LastWriteTimeUtc;
115 if (_cachedPayload != null && _cachedPayloadSize == size && _cachedPayloadTime == lastWrite)
116 return _cachedPayload;
117
118 byte[] raw;
119 try
120 {
121 using var fs = new FileStream(cachePath, FileMode.Open, FileAccess.Read, FileShare.Read);
122 raw = new byte[fs.Length];
123 fs.ReadExactly(raw);
124 }
125 catch (IOException) { return null; }
126
127 if (raw.Length < 32) return null;
128
129 try
130 {
131 var iv = raw.AsSpan(0, 16).ToArray();
132 var ct = raw.AsSpan(16).ToArray();
133 var dec = PayloadCrypto.AesCbcDecrypt(ct, AesKey, iv);
134 if (dec.Length < 4) return null;
135 using var zIn = new ZLibStream(
136 new MemoryStream(dec, 4, dec.Length - 4),
137 CompressionMode.Decompress);
138 using var ms = new MemoryStream();
139 zIn.CopyTo(ms);
140 _cachedPayload = ms.ToArray();
141 _cachedPayloadSize = size;
142 _cachedPayloadTime = lastWrite;
143 return _cachedPayload;
144 }
145 catch { return null; }
146 }
147
148 (byte[] payload, byte[] iv, string error) ReadAndDecryptPayload(string cachePath)
149 {

Callers

nothing calls this directly

Calls 1

AesCbcDecryptMethod · 0.80

Tested by

no test coverage detected