I use below code to encrypt and decrypt file in B4A,all is fine:
In b4i, I Decrypt one file Encrypted in B4A,it not work and has no error.
I have encrypted the files in B4A and applied them to the project for some time now. I tried to use encrypted files in B4I(I only change "Dim enc As B4XCipher" to "Dim enc As Cipher"), but it seems that the above decryption method is not feasible. How can I modify the decryption method in B4i?
Encrypt and decrypt file in B4A:
Sub EncryptFile (Path As String, Password As String)
Dim size As Long = File.Size(Path, "")
Dim rafInput, rafOutput As RandomAccessFile
rafInput.Initialize(Path, "", True)
rafOutput.Initialize(Path & ".enc", "", False)
Dim enc As B4XCipher
Dim buffer(2024 * 1024) As Byte
Do While rafInput.CurrentPosition < size
Dim count As Int = rafInput.ReadBytes(buffer, 0, Min(buffer.Length, size - rafInput.CurrentPosition), rafInput.CurrentPosition)
Dim b() As Byte
If count = buffer.Length Then
b = buffer
Else
Dim b(count) As Byte
Bit.ArrayCopy(buffer, 0, b, 0, count)
End If
Dim bb() As Byte = enc.Encrypt(b, Password)
rafOutput.WriteInt(bb.Length, rafOutput.CurrentPosition)
rafOutput.WriteBytes(bb, 0, bb.Length, rafOutput.CurrentPosition)
Sleep(30)
Loop
rafInput.Close
rafOutput.Close
End Sub
Sub DecryptFile (Path As String, Password As String)
Dim size As Long = File.Size(Path, "")
Dim rafInput, rafOutput As RandomAccessFile
rafInput.Initialize(Path, "", True)
rafOutput.Initialize(Path & ".decrypted", "", False)
Dim b() As Byte
Dim enc As B4XCipher
Do While rafInput.CurrentPosition < size
Dim blockLength As Int = rafInput.ReadInt(rafInput.CurrentPosition)
If b.Length <> blockLength Then
Dim b(blockLength) As Byte
End If
rafInput.ReadBytes(b, 0, b.Length, rafInput.CurrentPosition)
Dim bb() As Byte = enc.Decrypt(b, Password)
rafOutput.WriteBytes(bb, 0, bb.Length, rafOutput.CurrentPosition)
Sleep(30)
Loop
rafInput.Close
rafOutput.Close
End Sub
In b4i, I Decrypt one file Encrypted in B4A,it not work and has no error.
Decrypt in B4i:
Sub DecryptFile(Path As String, Password As String)
Dim size As Long = File.Size(Path, "")
Dim rafInput, rafOutput As RandomAccessFile
rafInput.Initialize(Path, "", True)
rafOutput.Initialize(Path & ".decrypted", "", False)
Dim b() As Byte
Dim enc As Cipher
Do While rafInput.CurrentPosition < size
Dim blockLength As Int = rafInput.ReadInt(rafInput.CurrentPosition)
If b.Length <> blockLength Then
Dim b(blockLength) As Byte
End If
rafInput.ReadBytes(b, 0, b.Length, rafInput.CurrentPosition)
Dim bb() As Byte = enc.Decrypt(b, Password)
rafOutput.WriteBytes(bb, 0, bb.Length, rafOutput.CurrentPosition)
Sleep(30)
Loop
rafInput.Close
rafOutput.Close
End Sub
I have encrypted the files in B4A and applied them to the project for some time now. I tried to use encrypted files in B4I(I only change "Dim enc As B4XCipher" to "Dim enc As Cipher"), but it seems that the above decryption method is not feasible. How can I modify the decryption method in B4i?