hi I ned encrypt/decrypt a string. example
string = alfonso pascual herrejon
wen i push a button encrypt the string and wen push otter button decrypt de same string this is my code
but wen push decrypted button the program stop in line
helpme plis, sorry my bad english
and tanks
string = alfonso pascual herrejon
wen i push a button encrypt the string and wen push otter button decrypt de same string this is my code
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim txtescritura As EditText
Dim txtdecodifica As EditText
Dim Bconv As ByteConverter
Dim temp(0) As Byte
Dim key(0) As Byte
Dim data(0) As Byte
Dim iv(0) As Byte
Dim B64 As Base64
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("encdec")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btncodifica_Click
Dim kg As KeyGenerator
Dim c As Cipher
Dim B64 As Base64
Dim Bconv As ByteConverter
Dim data(0) As Byte
Dim iv(0) As Byte
iv = "(=Lo78&@".GetBytes("ASCII")
c.Initialize("DES/CBC/PKCS5Padding")
c.InitialisationVector = iv
kg.Initialize("DES")
kg.GenerateKey
key = kg.KeyToBytes
Msgbox(Bconv.HexFromBytes(key), "Key " & key.Length & " bytes")
clear = "alfonso pascual herrejon"
data = Bconv.StringToBytes(clear, "UTF8")
data = c.Encrypt(data, kg.key, True)
temp = data
txtescritura.Text = Bconv.HexFromBytes(data)
'Msgbox(Bconv.HexFromBytes(data), "Encrypted is " & data.Length & " bytes")
End Sub
Sub btndecodifica_Click
Dim kg As KeyGenerator
Dim c As Cipher
Dim B64 As Base64
Dim Bconv As ByteConverter
Dim data(0) As Byte
Dim iv(0) As Byte
iv = "(=Lo78&@".GetBytes("ASCII")
c.Initialize("DES/CBC/PKCS5Padding")
c.InitialisationVector = iv
kg.Initialize("DES")
kg.GenerateKey
key = kg.KeyToBytes
data = temp
data = c.Decrypt(data, kg.key, True)
Msgbox(Bconv.StringFromBytes(data, "UTF8"), "Decrypted")
End Sub
but wen push decrypted button the program stop in line
B4X:
data = c.Decrypt(data, kg.key, True)
helpme plis, sorry my bad english