Back to "Di più sul mio viaggio nel meraviglioso mondo di ASP.NET 1.x ViewState"

This is a viewer only at the moment see the article on how this works.

To update the preview hit Ctrl-Alt-R (or ⌘-Alt-R on Mac) or Enter to refresh. The Save icon lets you save the markdown file to disk

This is a preview from the server running through my markdig pipeline

ASP.NET Imported mostlylucidcouk Security

Di più sul mio viaggio nel meraviglioso mondo di ASP.NET 1.x ViewState

Sunday, 29 February 2004

Ho scritto in un Post precedente che stavo progettando di fare un giro con VisualizzaStato, estendere le cose che ho fatto sulla compressione in crittografia e firma ecc ... bene ci sono buone e cattive notizie per questo piano. Sembra (spesso) che la roba MAC e crittografia è effettivamente gestito nella classe LosWriter; una classe interna utilizzata da LosFormatterCity name (optional, probably does not need a translation) per fare realmente la serializzazione dell'oggetto... usa il seguente codice per fare questo (grazie ancora una volta all'indispensabile Riflettore) :

internal void CompleteTransforms(TextWriter output, bool enableMac, byte[] macKey)
{ int num1;
byte[] array1;
string text1;
char[] array2;
string text2;
num1 = 0;
if (this._recyclable)
{
 this._byteBuffer = ((byte[]) LosWriter._byteBufferAllocator.GetBuffer());
if (this._freePos > 0)
{
 num1 = Encoding.UTF8.GetBytes(this._charBuffer, 0, this._freePos, this._byteBuffer, 0);
 
}
if (enableMac)
{
 array1 = MachineKey.GetEncodedData(this._byteBuffer, macKey, 0, &(num1));
text1 = Convert.ToBase64String(array1, 0, num1);
output.Write(text1);
return; 
}
array2 = ((char[]) LosWriter._charBufferAllocatorBase64.GetBuffer());
num1 = Convert.ToBase64CharArray(this._byteBuffer, 0, num1, array2, 0);
output.Write(array2, 0, num1);
LosWriter._charBufferAllocatorBase64.ReuseBuffer(array2);
return; 
}
this._byteBuffer = Encoding.UTF8.GetBytes(this._charBuffer, 0, this._freePos);
num1 = this._byteBuffer.Length;
if (enableMac)
{
 this._byteBuffer = MachineKey.GetEncodedData(this._byteBuffer, macKey, 0, &(num1));
 
}
text2 = Convert.ToBase64String(this._byteBuffer);
output.Write(text2);
 
}

Come probabilmente potete vedere, questo codice gestisce l'applicazione della chiave MAC e la crittografia ai dati serializzati. Questo è il codice utilizzato dalla 'MachineKey' per eseguire la crittografia:

internal static byte[] EncryptOrDecryptData(bool fEncrypt, byte[] buf, byte[] modifier, int start, int length)
{ MemoryStream stream1;
ICryptoTransform transform1;
CryptoStream stream2;
byte[] array1;
byte[] array2;
MachineKey.EnsureConfig();
stream1 = new MemoryStream();
transform1 = MachineKey.GetCryptoTransform(fEncrypt);
stream2 = new CryptoStream(stream1, transform1, 1);
stream2.Write(buf, start, length);
if (fEncrypt && (modifier != null))
{
 stream2.Write(modifier, 0, modifier.Length);
 
}
stream2.FlushFinalBlock();
array1 = stream1.ToArray();
stream2.Close();
MachineKey.ReturnCryptoTransform(fEncrypt, transform1);
if (!fEncrypt && (modifier != null))
{
 array2 = new byte[((uint) (array1.Length - modifier.Length))];
Buffer.BlockCopy(array1, 0, array2, 0, array2.Length);
array1 = array2;
 
}
return array1; 
} 

Purtroppo, questo significa che o dovrò giocare con riflessione / scaricare la fonte da Refelector / completamente reinventare come questo funziona per andare molto oltre con il mio VisualizzaState armeggiare, dio sarebbe stato bello se questa roba fosse stata fatta con una fabbrica originariamente ... immagino che non avrebbero pensato nessuno sarebbe stato abbastanza pazzo per voler giocare con esso ...:-)

Alla fine dovrò arrendersi e scrivere un articolo uno di questi giorni... problema per me è strutturare la cosa così è leggibile per gli esseri umani non ossessivi...

logo

© 2026 Scott Galloway — Unlicense — All content and source code on this site is free to use, copy, modify, and sell.