help wit sub

charro98120165

Member
Licensed User
Longtime User
I HAVE a string

clear = "1:11;2:SUC_0001;3:MAQ_0001;4:00-0A-EB-54-92-57;5:RECING;6:VF;13:EQUIPO1;14:1000"

how call the sub

B4X:
Sub Encrypt(dataToEncrypt As String ) As String

   Dim kg As KeyGenerator
   Dim c As Cipher
   Dim key(0) As Byte
   Dim data(0) As Byte
   Dim iv(0) As Byte
   
   iv = "(=Lo78&@".GetBytes("ASCII") ' 16 bytes for AES
   
   c.Initialize("DES/CBC/PKCS5Padding") ' replace "DES/" with "AES/" for Rijndael or "DESEDE/" for triple DES
   
   ' CBC needs an initialisation vector
   c.InitialisationVector = iv
   kg.Initialize("DES") ' replace "DES" with "AES" for Rijndael or "DESEDE" for triple DES
   kg.KeyFromBytes(Bconv.StringToBytes("(=Lo78&@","ASCII"))
   key = kg.KeyToBytes
   Msgbox(Bconv.HexFromBytes(key), "Key " & key.Length & " bytes")
   data = Bconv.StringToBytes(dataToEncrypt, "UTF8")
   data = c.Encrypt(data, kg.key, True)   
   Msgbox(Bconv.HexFromBytes(data), "Encrypted is " & data.Length & " bytes")
   Return 
   
   End Sub

and realize the encryption ?? tanks
 
Top