FBEncrypter library compatibility with Android

I have already used below library to decrypt encryption in ios .

https://github.com/dev5tec/FBEncryptor

Now I want the same functionality in android . Is there support for android as well. if not how can I use this library to meet my android need as well, or if you can suggest me another other encryption library that works the same as FBEncryptor then it is very helpful for me.

i have executed the 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 it is throwing javax.crypto.BadPaddingException: Corrupt lock block

If you have any suggestions or solutions please help me.

+3


source to share


1 answer


Finally, I found a solution for my own question.

For encryption in android you can use https://gist.github.com/m1entus/f70d4d1465b90d9ee024 .



This class works the same as https://github.com/dev5tec/FBEncryptor in ios .

+3


source







All Articles