encryption - FBEncrypter library compatibility with android -
i have use below library encryption decryption in ios.
https://github.com/dev5tec/fbencryptor
now want same functionality in android. there support android . if not how can use library fulfil need in android or if can suggest me other encryption library work same fbencryptor helpful me.
i have implemented following code.
public class aeshelper { private final cipher cipher; private final secretkeyspec key; private algorithmparameterspec spec; private static final string key = "vhjftfrgjhghjdhkhjhd/dhfdh="; public aeshelper() throws exception { byte[] keybytes = key.getbytes("utf-8"); arrays.fill(keybytes, (byte) 0x00); cipher = cipher.getinstance("aes/cbc/pkcs7padding"); key = new secretkeyspec(keybytes, "aes"); spec = getiv(); } public algorithmparameterspec getiv() { final byte[] iv = new byte[16]; arrays.fill(iv, (byte) 0x00); return new ivparameterspec(iv); } public string encrypt(string plaintext) throws exception { cipher.init(cipher.encrypt_mode, key, spec); byte[] encrypted = cipher.dofinal(plaintext.getbytes("utf-8")); string encryptedtext = new string(base64.encode(encrypted, base64.default), "utf-8"); return encryptedtext; } public string decrypt(string cryptedtext) throws exception { cipher.init(cipher.decrypt_mode, key, spec); byte[] bytes = base64.decode(cryptedtext, base64.default); byte[] decrypted = cipher.dofinal(bytes); string decryptedtext = new string(decrypted, "utf-8"); return decryptedtext; } }
but throw javax.crypto.badpaddingexception: pad block corrupted
if have suggestion or solution please me .
finally have found solution own question.
for encryption in android can use https://gist.github.com/m1entus/f70d4d1465b90d9ee024.
this class work same https://github.com/dev5tec/fbencryptor in ios.
Comments
Post a Comment