Android Question Decryption library question

grafsoft

Well-Known Member
Licensed User
Longtime User
As I said - I need some different files put into one, graphics, sound and numbers, and encrypt them, send them to a PHP server and decrypt the whole story there. That would be easy with RandomAccessFile, but as I understand PHP does not decrypt it properly. The library https://www.b4x.com/android/forum/t...ding-compatible-php-code-to-de-encrypt.52582/ does it well, I checked it. But it needs strings. Compression would also be nice.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
does it well, I checked it. But it needs strings
You can try the encrypt2 method (use the lib attached)

i did not test it as yet... If you do and you confirm it work i´ll do the same for the decrypting part (it is not done as yet)
 

Attachments

  • Decrypterv1.0.2.zip
    7 KB · Views: 290
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
I think it does not work yet.

B4X:
   crypt.Initialize("aaaaaaaaaaaaaaaa","6666666666666666")
   d=File.Size (Main.outdir,fname)
   Log (d)
   ' proves that the file exists
   Dim data() As Byte = Bit.InputStreamToBytes(File.OpenInput(Main.outdir,fname))
   t=Main.crypt.encrypt2 (data) ' error

Error occurred on line: 667 (Basis)
Message longer than Log limit (4000). Message was truncated.
java.lang.Exception: [encrypt] error:0607F08A:digital envelope routines:EVP_EncryptFinal_ex:data not multiple of block length
at de.donmanfred.MCrypt.encrypt2(MCrypt.java:55)
at de.donmanfred.CrypterWrapper.encrypt2(CrypterWrapper.java:61)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at it.giuseppe.salvi.PhotoGalleryViewActivity$1.onItemClick(PhotoGalleryViewActivity.java:83)
at android.widget.AdapterView.performItemClick(AdapterView.java:300)
at android.widget.Gallery.onSingleTapUp(Gallery.java:985)
at android.view.GestureDetector.onTouchEvent(GestureDetector.java:595)
at android.widget.Gallery.onTouchEvent(Gallery.java:962)
at android.view.View.dispatchTouchEvent(View.java:8393)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2426)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2158)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2432)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2432)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2432)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2432)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2314)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1692)
at android.app.Activity.dispatchTouchEvent(Activity.java:2749)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2275)
at android.view.View.dispatchPointerEvent(View.java:8583)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4091)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3957)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3509)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3562)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3528)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3638)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3536)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3695)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3509)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3562)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3528)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3536)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3509)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5806)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5745)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5716)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5896)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:192)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:143)
at android.os.Looper.loop(Looper.java:122)
at android.app.ActivityThread.main(ActivityThread.java:5312)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Me
Message longer than Log limit (4000). Message was truncated.
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **


Method Crypt works

B4X:
   Dim teststring As String = "DonManfred"
   Dim crypted As String = crypt.encrypt(teststring)
   Log(crypted)
   Dim t As String
   t=hostname & "_decrypt.php?p=" & crypted
   pjob.Download (t)
   ' php method works
   Dim decrypted As String = crypt.decrypt(crypted)
   Log(decrypted) ' this method works as well

But thanks a lot for trying!
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Please try the libversion attached

B4X:
    Dim fsize As Int = File.Size (File.Combine(File.DirRootExternal,"Download/"),"09 - Dire Straits - Brothers in Arms.mp3")
  Log (fsize)
  ' proves that the file exists
  Dim data() As Byte = Bit.InputStreamToBytes(File.OpenInput(File.Combine(File.DirRootExternal,"Download/"),"09 - Dire Straits - Brothers in Arms.mp3"))
    Dim t As String = crypt.encrypt2(data) ' e   
    Log(t)
works for me with THIS version....

But i have not checked if the php is still compatible.

i´ve changed the initialization of the crypt-engine from
B4X:
cipher = Cipher.getInstance("AES/CBC/NoPadding");
to
B4X:
cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
 

Attachments

  • libDecrypterV1.0.5.zip
    3.6 KB · Views: 308
Upvote 0
Top