B4J Question Encryption problem

JakeBullet70

Well-Known Member
Licensed User
Longtime User
Hi all.

Anybody see an issue with this code? I write the map file out encrypted and when I look at in Notepad++ you can see it is encrypted. But when I read it back in it comes is wrong.


B4X:
Sub Process_Globals
    Private fx As JFX
    Private Const PASSWORD0 As String = "xciFp987q"
    Private Const PASSWORD1 As String = "jav!a"
    Private const DEV0EMAIL As String = "lo@(W" '--- 3rd part of PW
    Dim PASSWORD As String = PASSWORD0 & "7" &  PASSWORD1 & "U" & DEV0EMAIL
End Sub

Sub SaveMapFiles(filename As String, m As Map,encreypted As Boolean)
    SafeKill(File.DirApp,filename)
    If encreypted Then
        Dim raf As RandomAccessFile
        raf.Initialize(File.DirApp,filename,False)
        'raf.WriteB4XObject(m,raf.CurrentPosition)
        raf.WriteEncryptedObject(m , PASSWORD,raf.CurrentPosition)
        raf.Close
    Else  
        File.WriteMap(File.DirApp,filename,m)
    End If
End Sub

Sub LoadMapFile(filename As String,encreypted As Boolean) As Map
    Dim m As Map : m.Initialize
    If encreypted Then
        Dim raf As RandomAccessFile
        raf.Initialize(File.DirApp,filename,False)
        'm = raf.ReadB4XObject(raf.CurrentPosition)  
        m = raf.ReadEncryptedObject(PASSWORD,raf.CurrentPosition)  
        raf.Close
    Else
        m = File.ReadMap(File.DirApp,filename)      
    End If
  
    Return m
End Sub


upload_2016-6-4_11-30-51.png
 
Last edited:

udg

Expert
Licensed User
Longtime User
Hi,
I can't see a raf.close statement after the write. Is it in the code calling SaveMapFiles?
 
Upvote 0

udg

Expert
Licensed User
Longtime User
So, you solved it? What did cause the problem?

udg
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Definitely ,you're not alone in having spent countless hours for distraction, "should have known that" or simply because of too many hours at the keyboard.. it happens! :)
 
Upvote 0
Top