기타 [vb.net] 암호 키생성 및 암호화 복호화
페이지 정보

본문
암호 키생성:)
    Dim RandomValue As New Random
    Public Function NewKeys() As String
        Dim value As New List(Of String)
        Dim i As Integer, n As Integer, T As String
        Dim x As New Collection
        Do
            n = RandomValue.Next(0, 256)
            If xAdd(x, n) Then
                value.Add(n)
            End If
        Loop Until value.Count > 255
        T = Join(value.ToArray, ",")
        T &= vbCrLf
        For i = 0 To 255
            For n = 0 To 255
                If value(n) = i.ToString Then
                    T &= n
                    T &= IIf(i <> 255, ",", "")
                    Exit For
                End If
            Next
        Next
        Return T
    End Function
암호화:)
 
    Public Function EnCryptString(ByVal value As String) As String
        Dim strValue As Int32
        Dim EnKey() As Integer = (From str In Split(My.Resources.enkey, ",")
                                  Let isInt = Int32.TryParse(str, strValue)
                                  Where isInt
                                  Select Int32.Parse(str)).ToArray
        Dim B() As Byte = System.Text.Encoding.UTF8.GetBytes(value)
        For i = 0 To B.Length - 1
            B(i) = EnKey(B(i))
        Next
        Return Replace(BitConverter.ToString(B, 0), "-", "")
    End Function
복호화:)
    Public Function DeCryptString(ByVal value As String) As String
        Dim strValue As Int32
        Dim DeKey() As Integer = (From str In Split(My.Resources.dekey, ",")
                                  Let isInt = Int32.TryParse(str, strValue)
                                  Where isInt
                                  Select Int32.Parse(str)).ToArray
        Dim Result As New List(Of Byte)
        For i = 0 To value.Length - 1 Step 2
            Result.Add(Convert.ToByte(value.Substring(i, 2), 16))
        Next
        Dim B() As Byte = Result.ToArray
        For i = 0 To B.Length - 1
            B(i) = DeKey(B(i))
        Next
        Return System.Text.Encoding.UTF8.GetString(B)
    End Function
- 이전글[vb.net] Cookie 유지 및 갱신 19.10.08
 - 다음글[vb.net] 파일 삭제 File.Delete / Directory.Exists 19.10.08
 
댓글목록
등록된 댓글이 없습니다.



