Private Sub EncryptFile(inPath As String, outPath As String, encKey As String) As Boolean
Dim enc As B4XCipher
Dim result As Boolean
Dim rafInput, rafOutput As RandomAccessFile
TextArea1.Text = TextArea1.Text & CRLF & "Input file to encrypt: " & inPath & CRLF & "Encrypted output file: " & outPath
If File.Exists(outPath, "") Then File.Delete(outPath, "")
rafInput.Initialize(inPath, "", True)
rafOutput.Initialize(outPath, "", False)
Try
Dim size As Long = File.Size(inPath, "")
Dim b(size) As Byte
rafInput.ReadBytes(b, 0, size, 0)
Dim bb() As Byte = enc.Encrypt(b, encKey)
rafOutput.WriteBytes(bb, 0, bb.Length, rafOutput.CurrentPosition)
result = True
Catch
TextArea1.Text = TextArea1.Text & CRLF & LastException
result = False
End Try
rafInput.Close
rafOutput.Close
Return result
End Sub
Private Sub DecryptFile(inPath As String, outPath As String, encKey As String) As Boolean
Dim enc As B4XCipher
Dim result As Boolean
Dim rafInput, rafOutput As RandomAccessFile
TextArea1.Text = TextArea1.Text & CRLF & "Input file to decrypt: " & inPath & CRLF & "Decrypted output file: " & outPath
If File.Exists(outPath, "") Then File.Delete(outPath, "")
rafInput.Initialize(inPath, "", True)
rafOutput.Initialize(outPath, "", False)
Try
Dim size As Long = File.Size(inPath, "")
Dim b(size) As Byte
rafInput.ReadBytes(b, 0, size, 0)
Dim bb() As Byte = enc.Decrypt(b, encKey)
rafOutput.WriteBytes(bb, 0, bb.Length, 0)
result = True
Catch
TextArea1.Text = TextArea1.Text & CRLF & LastException
result = False
End Try
rafInput.Close
rafOutput.Close
Return result
End Sub