Android Question [solved] Encryption Lib: 0606506D:digital envelope routines:

KMatle

Expert
Licensed User
Longtime User
I am getting this error

javax.crypto.IllegalBlockSizeException: error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length

when I try to decrypt a text longer than 16 chars.

Here's the code:

B4X:
Sub Decrypt(encryptedData As String ) As String

  Dim kg As KeyGenerator
  Dim c As Cipher
  Dim B64 As Base64
  Dim bconv As ByteConverter
  Dim md As MessageDigest
  Dim p As String
  Dim data(0) As Byte
  Dim iv(0) As Byte
  Dim vec As String
  vec=filevec
  p=filepw
 
  iv = vec.GetBytes("UTF8")
 
  c.Initialize("DESEDE/CBC/PKCS5Padding")   
  c.InitialisationVector = iv
 
  kg.Initialize("DESEDE")   
  kg.KeyFromBytes(md.GetMessageDigest(p.GetBytes("UTF8"), "MD5"))
 
  Try
      data = B64.DecodeStoB(encryptedData)
          data = c.Decrypt(data, kg.Key, True)
      Return bconv.StringFromBytes(data, "UTF8")
    Catch
      Msgbox(LastException.Message, "Decode not possible")
      Return "Nope"
    End Try

As I've understood it, there's a problem with padding. Could someone help me out with that? I don't want to try&error with this (changing parameters to NoPadding, etc.)
 
Top