Perhaps, there is someone who needs it: I made a simple encryption from string to string for b4j, b4a and b4i.
First, the string is encrypted with the b4xEncryption, after that, the bytes are changed to a base64-string and this string is changed to a url-able string.
Needed libraries:
B4J: Byteconverter, jB4XEncryption, jStringUtils
B4A: StringUtils, ByteConverter, B4XEncryption
B4I: iEncryption, iRandomAccessfile, iStringUtils
First, the string is encrypted with the b4xEncryption, after that, the bytes are changed to a base64-string and this string is changed to a url-able string.
Needed libraries:
B4J: Byteconverter, jB4XEncryption, jStringUtils
B4A: StringUtils, ByteConverter, B4XEncryption
B4I: iEncryption, iRandomAccessfile, iStringUtils
B4X:
Sub Process_Globals
Dim Cipher As B4XCipher 'B4J and B4A
Dim Cipher as Cipher 'B4I
Dim su As StringUtils
Dim bc As ByteConverter
Dim Password As String ="blabla"
End Sub
Sub AppStart (Form1 As Form, Args() As String) / Activity_Create(FirstTime As Boolean) / Application_Start (Nav As NavigationController)
Dim Ergebnis As String
Ergebnis=encrypt("12345")
Log(Ergebnis)
Log(decrypt(Ergebnis))
End Sub
'Verschlüsselung der Zeichenkette mit AES, dann die verschlüsselten Bytes in Base64-String wandeln und anschliessend diesen String in ein URL-Format wandeln'
Sub encrypt(Zeichenkette As String) As String
Return su.EncodeUrl(su.encodeBase64(Cipher.Encrypt(Zeichenkette.GetBytes("UTF8"), Password)), "UTF8")
End Sub
'Den URL-String wieder dekodieren, anschliessend die Base64-Zeichenkette in Bytes wandeln und dann entschlüsseln. Die entschlüsselten Bytes wieder in einen String wandeln und zurück geben'
'In B4I wird der String mit chr(0) aufgefüllt. Diese vor der Rückgabe wieder entfernen'
Sub decrypt (Zeichenkette As String) As String
Zeichenkette=bc.StringFromBytes(Cipher.Decrypt(su.DecodeBase64(su.DecodeUrl(Zeichenkette, "UTF8")), Password),"UTF8")
If Zeichenkette.Contains(Chr(0)) Then Zeichenkette=Zeichenkette.SubString2(0, Zeichenkette.IndexOf(Chr(0)))
Return Zeichenkette
End Sub
Last edited: