[vb.net] 암호 키생성 및 암호화 복호화 > vb.net

본문 바로가기

vb.net

[기타] [vb.net] 암호 키생성 및 암호화 복호화

회원사진
하나를하더라도최선을
2019-10-08 21:53 8,522 0

본문



암호 키생성:)
    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(0256)
            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 StringAs 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 StringAs 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

댓글목록0

등록된 댓글이 없습니다.
게시판 전체검색