hi all
in mysql , i encrypt the field name1 into the field name :
but in b4j :
when i use encryption library with the code :
i get the following error at the line : Dim bytEn() As Byte = Cipher.Decrypt(byt,kg.key,False)
in mysql , i encrypt the field name1 into the field name :
that is working fine decrypting :update `persons` set `Name` = TO_BASE64(AES_ENCRYPT(`Name1`,'pwd'))
select CONVERT(AES_DECRYPT(FROM_BASE64(`Name`),'pwd') USING utf8) as n from persons where `FileNo` = 3
but in b4j :
when i use encryption library with the code :
B4X:
Sub decrypt(MeText As String) As String
Dim kg As KeyGenerator
Dim su As StringUtils
Dim Cipher As Cipher
Dim iv(0) As Byte
iv = Array As Byte(1,1, 2,2, 3,3, 4,4, 5,5, 6,6, 7,7, 8,8) ' 16 bytes for AES
Dim byt() As Byte = su.DecodeBase64(MeText)
Dim k() As Byte = "pwd".GetBytes("UTF8")
kg.Initialize("AES")
kg.KeyFromBytes(k)
Cipher.Initialize("AES/CBC/PKCS5Padding")
Cipher.InitialisationVector = iv
Dim bytEn() As Byte = Cipher.Decrypt(byt,kg.key,False)
Return BytesToString(bytEn,0,bytEn.Length,"UTF-8")
End Sub
i get the following error at the line : Dim bytEn() As Byte = Cipher.Decrypt(byt,kg.key,False)
Error occurred on line: 2113 (Codes)
javax.crypto.BadPaddingException: Given final block not properly padded
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:989)
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:845)
at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:446)
at javax.crypto.Cipher.doFinal(Cipher.java:2165)
at anywheresoftware.b4a.agraham.encryption.CipherWrapper.doFinal(CipherWrapper.java:140)
at anywheresoftware.b4a.agraham.encryption.CipherWrapper.Decrypt(CipherWrapper.java:150)
at b4j.example.codes._decrypt(codes.java:2039)
at b4j.example.main._getone1(main.java:14919)
at b4j.example.main._jobdone(main.java:18213)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:612)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:229)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
at sun.reflect.GeneratedMethodAccessor19.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:462)
at anywheresoftware.b4a.keywords.Common.access$0(Common.java:442)
at anywheresoftware.b4a.keywords.Common$CallSubDelayedHelper.run(Common.java:516)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)