Android Question [SOLVED] Error in MD 5 Decryption K2 Plugin Item Image

Puthut Wibowo

Member
Licensed User
Hello, all

I have a problem with the Libary MessageDigest (Encryption), I tried String Encryption to MD5 with success. But when I try to descrypt the program code it looks like an error. following the program code

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim crypt As Crypter
End Sub

Sub Activity_Create(FirstTime As Boolean)

EnscryptMD5
DescryptMD5
End Sub

Sub EnscryptMD5

Private pi As String
pi = "Image34"
Dim md As MessageDigest
Dim ByteCon As ByteConverter
Dim passwordhash() As Byte

passwordhash = md.GetMessageDigest(pi.GetBytes("UTF8"),"MD5")
Dim md5string As String
md5string = ByteCon.HexFromBytes(passwordhash)
md5string = md5string.ToLowerCase
Log("md5string : " & md5string)
'Result = f710044bf79a4b1f5d8b085e5e5d9711
End Sub

Sub DescryptMD5

Private pi As String
' Decrypt
pi = "f710044bf79a4b1f5d8b085e5e5d9711"
Dim md As MessageDigest
Dim ByteCon As ByteConverter
Dim passwordhash() As Byte
passwordhash = md.GetMessageDigest(pi.GetBytes("MD5"),"UTF8")
Dim md5string As String
md5string = ByteCon.HexToBytes(passwordhash)
md5string = md5string.ToLowerCase
Log("DescryptMD5 : " & md5string)

End Sub

any suggestions about this descryption code?
 
Last edited:

Puthut Wibowo

Member
Licensed User
I'm trying to reverse from MD5 to a format string.

If previously using the following code, convert String = "Image34" and the result is = f710044bf79a4b1f5d8b085e5e5d9711
String to MD5:
Sub EnscryptMD5
Private pi As String
pi = "Image34"
Dim md As MessageDigest
Dim ByteCon As ByteConverter
Dim passwordhash() As Byte

passwordhash = md.GetMessageDigest(pi.GetBytes("UTF8"),"MD5")
Dim md5string As String
md5string = ByteCon.HexFromBytes(passwordhash)
md5string = md5string.ToLowerCase
Log("md5string : " & md5string)
'Result = f710044bf79a4b1f5d8b085e5e5d9711
End Sub

Now I want to reverse the format to the form String = "Image34" with the following code

MD5 to UTF-8:
Sub DescryptMD5
    Private pi As String
    ' Decrypt
    pi = "f710044bf79a4b1f5d8b085e5e5d9711"
    Dim md As MessageDigest
    Dim ByteCon As ByteConverter
    Dim passwordhash() As Byte
    passwordhash = md.GetMessageDigest(pi.GetBytes("MD5"),"UTF8")
    Dim md5string As String
    md5string = ByteCon.HexToBytes(passwordhash)
    md5string = md5string.ToLowerCase
    Log("DescryptMD5 : " & md5string)

End Sub

Error message
Error:
 Error
B4A line: 92
md5string = ByteCon.HexToBytes(passwordhash)
javac 1.8.0_162
src\b4a\example\main.java:492: error: no suitable method found for NumberToString(byte[])
_md5string = BA.NumberToString(_bytecon.HexToBytes(BA.NumberToString(_passwordhash)));
                                                     ^
    method BA.NumberToString(double) is not applicable
      (argument mismatch; byte[] cannot be converted to double)
    method BA.NumberToString(float) is not applicable
      (argument mismatch; byte[] cannot be converted to float)
    method BA.NumberToString(int) is not applicable
      (argument mismatch; byte[] cannot be converted to int)
    method BA.NumberToString(long) is not applicable
      (argument mismatch; byte[] cannot be converted to long)
    method BA.NumberToString(Number) is not applicable
      (argument mismatch; byte[] cannot be converted to Number)
1 error
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Hashing (like MD5) is used to

1. Get a unique and short fingerprint of the data. Like a checksum for a 5 MB file to check if the contents didn't change.

2. Mask a password to store it in a database. So if it is hacked, one does not know what it was (*)

3. Shorten a password to a specific length. F.e. AES-256 needs a 32 bytes long key. With SHA-256 hashing you get 32 bytes.

* = As Aeric has mentioned there are rainbow tables mapping hash values to it's original values as older hash algorythms produce the same hash value for a specifiv value. BCRYPT is used here as it generates different values each time.

Use B4XEncryption or AES-256 to have a strong encryption. Use the search to find a bunch of examples.
 
Last edited by a moderator:
Upvote 0

Puthut Wibowo

Member
Licensed User
Thank you All for the answer

Actually, I tried to integrate Joomla K2 with Android.

The problem is in Joomla I use the K2 Plugin, where the K2 Image Item database does not exist.

So in order not to damage the content on the website, I replicated 2 MD5 files and a 'Jpg' file.

Based on suggestions from the K2 Forum
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I suggest to learn the basics first

MD5 is a Hash-algoritm (explained above), NOT a Encryption; means there is nothing you can decrypt out of it!

If you, for ex., create a MD5 from a 5mb big Image file you´ll get a 32 byte MD5-String.
It you create a MD5 for a 100GB big ZIP file you´ll get a 32 Byte long MD5 too.
It you create a MD5 for the String "Hello world" you´ll get a 32 Byte long MD5 too.

In all cases you are NOT ABLE to get the original file back from the MD5 (unless you have a Rainbowtable (also stated above)).
 
Last edited:
Upvote 0
Top