Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It wasn't "Classic ASP" (which is the COM-heavy, VBScript-friendly platform that was popular from 1997 to 2003) but ASP.NET WebForms which used ViewState. ViewState itself was a Base64-encoded (not encrypted) representation of the page's controls' properties. This was done because HTML Forms don't transmit additional properties back to the server, only <code>&lt;input&gt;s</code>' <code>value=""</code> attributes, so the ViewState included things like a control's background color property (if it was set).</p> <p>In WebForms, developers could use ViewState validation MAC to ensure their viewstate data wasn't altered, but in practice it frequently broke down. If you search for "Validation of viewstate MAC failed" then you'll find countless discussions on how to workaround the issue. However that is an irrelevant point in my post.</p> <p>If you want to use a client form field as a roundtrip data vector, then that's perfectly fine, just do something like the code below.</p> <pre><code>class PageViewModel { public String SecretData; } public ActionResult Foo() { Byte[] someSecretData = GetIcbmLaunchCodes(); someSecretData = ArbitraryEncryptionAlgorithm( someSecretData ); // you can encrypt the data any way you want. I personally recommend a symmetric algorithm like AES or TripleDES. HashAlgorithm hashAlgo = new HMACSHA1(); hashAlgo.Key = /* Your private key for HMAC */ Byte[] hmac = hashAlgo.ComputeHash( someSecretData ); // when using SHA1, hmac will be 160 bits long, or 20 bytes. PageViewModel model = new PageViewModel(); model.SecretData = Convert.ToBase64String( hmac + someSecretData ); // array concatenation is an exercise for the reader return View( model ); } [HttpPost] public ActionResult Foo(PageViewModel model) { Byte[] postedData = Convert.FromBase64String( model.SecretData ); Byte[] hmac = postedData[0...20]; // array substring is an exercise for the reader Byte[] secretData = postedData[20...n]; // Now verify the secret data HashAlgorithm hashAlgo = new HMACSHA1(); hashAlgo.Key = /* Your private key for HMAC */ Byte[] hmac2 = hashAlgo.ComputeHash( secretData ); if( hmac2 != hmac ) { /* the data has been tampered with. */ } else { /* the data is unadulterated */ Byte[] originalSecretData = ArbitaryDecryptionAlgorithm( secretData ); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload