iOS Question ios obfuscated

tufanv

Expert
Licensed User
Longtime User
Hello

I know that obfuscation is not possilbe during compile with b4i is there any way to crypt,obfuscate etc some strings as in b4a ?

ty
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this B4J program (non-UI) to encrypt the string:
B4X:
#Region  Project Attributes
   #AdditionalJar: bcprov-jdk15on-150
#End Region

Sub Process_Globals
   
End Sub

Sub AppStart (Args() As String)
   ObfuscateString("innocent looking string", "string that you want to obfuscate")
End Sub

Sub ObfuscateString(key As String, str As String)
   Dim e As B4XCipher
   Dim bc As ByteConverter
   Log(bc.HexFromBytes(e.Encrypt(str.GetBytes("UTF8"), key)))
End Sub
It requires ByteConverter and jB4XEncryption libraries.

It will log the output. Right click on it and copy it to your B4i program. You can decrypt it with:
B4X:
Public Sub ds(key As String, raw As String) As String
   Dim c As Cipher
   Dim bc As ByteConverter
   Return bc.StringFromBytes(c.Decrypt(bc.HexToBytes(raw), key), "utf8")
End Sub
Libraries: iRandomAccessFile and iEncryption.
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
You can use this B4J program (non-UI) to encrypt the string:
B4X:
#Region  Project Attributes
   #AdditionalJar: bcprov-jdk15on-150
#End Region

Sub Process_Globals
  
End Sub

Sub AppStart (Args() As String)
   ObfuscateString("innocent looking string", "string that you want to obfuscate")
End Sub

Sub ObfuscateString(key As String, str As String)
   Dim e As B4XCipher
   Dim bc As ByteConverter
   Log(bc.HexFromBytes(e.Encrypt(str.GetBytes("UTF8"), key)))
End Sub
It requires ByteConverter and jB4XEncryption libraries.

It will log the output. Right click on it and copy it to your B4i program. You can decrypt it with:
B4X:
Public Sub ds(key As String, raw As String) As String
   Dim c As Cipher
   Dim bc As ByteConverter
   Return bc.StringFromBytes(c.Decrypt(bc.HexToBytes(raw), key), "utf8")
End Sub
Libraries: iRandomAccessFile and iEncryption.

this encrypts my url with some squares at the end

when I paste my encrypted string with key into b4i , I get in the logs some squares at the end of the url and it gives unspported url error at httpjob.
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
Try it with:
B4X:
Public Sub ds(key As String, raw As String) As String
   Dim c As Cipher
   Dim b() As Byte = c.Decrypt(bc.HexToBytes(raw), key)
   Dim s As String = BytesToString(b, 0, b.Length, "utf8")
   Dim i As Int = s.IndexOf(Chr(0))
   If i > -1 Then s = s.SubString2(0, i)
   Return s
End Sub
Thanks for answer , I tried with another snippet found on the forum at : https://www.b4x.com/android/forum/t...or-b4j-b4a-and-b4i-also-in-url.58773/#content

It works for me , is this as safe as this one ?
 
  • Like
Reactions: ajk
Upvote 0
Top