When I do the following:
- encrypt file X with B4J to new file Y, and
- decrypt file Y with B4A to new file Z, then
- new file Z is not identical to original file X
All other combinations (B4J -> B4J, B4A -> B4A, B4A -> B4J) appear to work correctly.
Environment:
- OS: Win 10 or Linux Mint with Wine (tried both)
- JDK: OpenJDK 19.0.2
- B4A: 13.40; relevant libs: B4XEncryption 1.00, RandomAccessFile 2.33
- B4J: 10.30; relevant libs: jB4XEncryption 1.00, jRandomAccessFile 2.35
Demo project attached and the relevant encryption/decryption methods added below. Any insight would be greatly appreciated!
- encrypt file X with B4J to new file Y, and
- decrypt file Y with B4A to new file Z, then
- new file Z is not identical to original file X
All other combinations (B4J -> B4J, B4A -> B4A, B4A -> B4J) appear to work correctly.
Environment:
- OS: Win 10 or Linux Mint with Wine (tried both)
- JDK: OpenJDK 19.0.2
- B4A: 13.40; relevant libs: B4XEncryption 1.00, RandomAccessFile 2.33
- B4J: 10.30; relevant libs: jB4XEncryption 1.00, jRandomAccessFile 2.35
Demo project attached and the relevant encryption/decryption methods added below. Any insight would be greatly appreciated!
B4X:
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
Attachments
Last edited: