vb.net加密解密方法

1.vb.net加密解密方法加密

Private Function getLicenseDate() As String
            Dim b() As Byte
            Dim path As String = Server.MapPath(Context.Request.ApplicationPath) & "License\"
            Try
                If Not System.IO.Directory.Exists(path) Then
                    System.IO.Directory.CreateDirectory(path)
                End If
            Catch ex As IO.IOException
                Page.ClientScript.RegisterStartupScript(Me.GetType(), "Alert", "<script>alert('對不起,你可能沒有建立文件夾的權限')</script>")
                Exit Function
            End Try
            Dim output As String
            Dim filePath As String = path & "License.dat"
            If File.Exists(filePath) Then
                Try
                    Dim fs As New FileStream(filePath, FileMode.Open)
                    Dim sr As New StreamReader(fs)
                    output = sr.ReadToEnd().ToString()
                    sr.Close()
                    fs.Close()
                    'output = Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(filePath))
                Catch ex As Exception
                    Page.ClientScript.RegisterStartupScript(Me.GetType(), "Alert", "<script>alert('讀取LIENCE文件異常!請取消勾選License文件夾下的License.dat的只讀屬性!')</script>")
                End Try
            Else
                Exit Function
            End If
            Try
                b = Convert.FromBase64String(output)
            Catch ex As Exception
                Page.ClientScript.RegisterStartupScript(Me.GetType(), "Alert", "<script>alert('對不起,,發生錯誤')</script>")
            End Try
            Try
                output = System.Text.Encoding.GetEncoding(-0).GetString(b)
                Dim startIndex As Integer = output.IndexOf("<ValidityDate>") + "<ValidityDate>".Length
                Dim endIndex As Integer = output.IndexOf("</ValidityDate>")
                Dim index As Integer = endIndex - startIndex
                If startIndex > 0 And endIndex > 0 And index > 0 Then
                    output = output.Substring(startIndex, index)
                Else
                    output = "-1"
                End If
            Catch ex As Exception
                Page.ClientScript.RegisterStartupScript(Me.GetType(), "Alert", "<script>alert('獲取License信息發生異常')</script>")
                output = ""
            End Try
            Return output

        End Function

 

 

 

2. viewstate 做用域是本頁面spa

相關文章
相關標籤/搜索