Hi, using the Encryption library with the following code, recovered from the forum, I can encrypt a string with a password and decrypt it
con B4A
to encrypt: Dim crypt As String= EncryptAES(testo, password)
to decrypt: Dim decrypt As String= DecryptAES(crypt,password)
thinking that the iEncryption library with B4i would behave in the same way, I entered the same code, but I get an error on the code
Dim kg As KeyGenerator, basically KeyGenerator is not supported iEncryption.
How to solve the problem? Can anyone help me?
con B4A
B4X:
Sub EncryptAES(strDataToEncrypt As String, strKey As String) As String
Dim SU As StringUtils
Dim kg As KeyGenerator
Dim C As Cipher
Dim md As MessageDigest
Dim encrypted() As Byte
kg.Initialize("AES")
kg.KeyFromBytes(md.GetMessageDigest(strKey.GetBytes("UTF8"), "MD5"))
C.Initialize("AES/ECB/PKCS5Padding")
encrypted = C.Encrypt(strDataToEncrypt.GetBytes("UTF8"), kg.Key, False)
Return SU.EncodeBase64(encrypted)
End Sub
Sub DecryptAES(strDataToDecrypt As String, strKey As String) As String
Dim SU As StringUtils
Dim kg As KeyGenerator
Dim C As Cipher
Dim md As MessageDigest
Dim Decrypted() As Byte
kg.Initialize("AES")
kg.KeyFromBytes(md.GetMessageDigest(strKey.GetBytes("UTF8"), "MD5"))
C.Initialize("AES/ECB/PKCS5Padding")
Dim Bytes() As Byte = SU.DecodeBase64(strDataToDecrypt)
Decrypted = C.Decrypt(Bytes, kg.Key, False)
Return BytesToString(Decrypted, 0, Decrypted.Length, "UTF8")
End Sub
to decrypt: Dim decrypt As String= DecryptAES(crypt,password)
thinking that the iEncryption library with B4i would behave in the same way, I entered the same code, but I get an error on the code
Dim kg As KeyGenerator, basically KeyGenerator is not supported iEncryption.
How to solve the problem? Can anyone help me?