Imports System.Security.Cryptography
Imports System.Text
Public Class MyScript
'Encryption
Public Function EncodePasswordToBase64(password As String) As String
Try
Dim encData_byte As Byte() = New Byte(password.Length - 1) {}
encData_byte = System.Text.Encoding.UTF8.GetBytes(password)
Dim encodedData As String = Convert.ToBase64String(encData_byte)
Return encodedData
Catch ex As Exception
Throw New Exception("Error in base64Encode" + ex.Message)
End Try
End Function
'Decryption
Public Function DecodeFrom64(encodedData As String) As String
Dim encoder As New System.Text.UTF8Encoding()
Dim utf8Decode As System.Text.Decoder = encoder.GetDecoder()
Dim todecode_byte As Byte() = Convert.FromBase64String(encodedData)
Dim charCount As Integer = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length)
Dim decoded_char As Char() = New Char(charCount - 1) {}
utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0)
Dim result As String = New [String](decoded_char)
Return result
End Function
End Class