machineKey を設定する
概要
machineKey を設定し、webサイトの viewState を暗号化する。
参照:
元ネタ:
前提条件
手順
default.aspx.vb を以下のように変更。
Imports System.Security.Cryptography
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Write("validationKey:")
Response.Write("<br>")
Response.Write(func_random(63))
Response.Write("<br>")
Response.Write("<br>")
Response.Write("decryptionKey:")
Response.Write("<br>")
Response.Write(func_random(23))
Response.Write("<br>")
End Sub
Protected Function func_random(ByVal length As Integer)
Dim random() As Byte = New Byte(length) {}
Dim rng As RNGCryptoServiceProvider = New RNGCryptoServiceProvider()
rng.GetBytes(random)
Dim s As String = ""
Dim b As Byte
For Each b In random : s += b.ToString("x2") : Next
s = s.ToUpper()
Return s
End Function
End Class
実行すると以下のように表示される。
なお、実行する毎に結果文字列が変化する。
なお、実行する毎に結果文字列が変化する。
not found (234.jpg)
上記の結果文字列をメモ帳等に保存しておき、
web.config に以下を追加する。
web.config に以下を追加する。
<configuration>
<system.web>
<machineKey validationKey="「結果文字列1」"
decryptionKey="「結果文字列2」"
validation="SHA1"/>
</system.web>
</configuration>
not found (232.jpg)