'Code module
'Subs in this code module will be accessible from all modules.
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim Bconv As ByteConverter
End Sub
Sub Get(Text As String, Mode As Int) As String 'mode= 0/1 = encode/decode
If Text = Null OR Text = "" Then Return ""
Dim key(0) As Byte
Dim data(0) As Byte
Dim bytes(0) As Byte
key = Array As Byte(3, 2, 4, 4, 7, 7, 15, 8) 'change this for you
Dim Kg As KeyGenerator
Dim c As Cipher
c.Initialize("DES/ECB/NoPadding") ' just "DES" actually performs "DES/ECB/PKCS5Padding".
Kg.Initialize("DES")
Kg.KeyFromBytes(key)
If Mode = 0 Then
Text = padString(Text)
data = Bconv.StringToBytes(Text, "UTF8")
data = c.Encrypt(data, Kg.key, False)
Return Bconv.HexFromBytes(data)
Else If Mode = 1 Then
data = Bconv.HexToBytes(Text)
bytes = c.Decrypt(data, Kg.key, False)
Return Bconv.StringFromBytes(bytes,"UTF8").Trim
End If
End Sub
Sub padString(source As String) As String
Dim paddingChar As String, size, x, padLength As Int
paddingChar = " "
size = 16
x = source.Length Mod size
padLength = size - x
For i = 0 To padLength - 1
source = source & paddingChar
Next
Return source
End Sub