B4R Question B4r Encrypt / Decrypt Data

takhmin77

Member
Last edited:

takhmin77

Member
hi
thanks for your answer
i want generate a one time password that is valid for my server and encrypt it
when server recives password , decrypts password and then it authenticates it (by an algorythm between client and server) , if decrypted password is valid , save URL values to its database.
i save recived password to server database , and when someone send again that password , i search in database and when i found that password ,message it "Password Not Valid" ..

is there any way to encrypt password ?
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Yes:
B4X:
Sub Process_Globals
   Public Serial1 As Serial
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("appstart")
   Dim encrypted() As Byte = EncryptDecrypt("abcdef", "d23,")
   Log(encrypted)
   Log(EncryptDecrypt(encrypted, "d23,"))
End Sub

Private Sub EncryptDecrypt(Text() As Byte, Pattern() As Byte) As Byte()
   Dim res(Text.Length) As Byte
   For i = 0 To Text.Length - 1
       res(i) = Bit.Xor(Text(i), Pattern(i Mod Pattern.Length))
   Next
   Return res
End Sub

This method is good for encryption of "random" data such as passwords. It is less secure if you use it with more predictable data such as a long text made of words.
 
Upvote 0
Top