Android encryption not working (PBKDF2WithHmacSHA256 encryption with AES/CBC/PKCS7Padding)

3.1k views Asked by At

I am trying to write an encryption code using Cipher Algorithm "AES/CBC/PKCS7Padding", HMAC algorithm "HmacSHA256" and key derivation algorithm "PBKDF2WithHmacSHA256" with the help of android JNCryptor. But it shows:

CryptorException: Failed to generate key from password using PBKDF2WithHmacSHA256

and

NoSuchAlgorithmException: SecretKeyFactory PBKDF2WithHmacSHA256 implementation not found

 try {
   SecretKeyFactory factory = SecretKeyFactory
     .getInstance(KEY_DERIVATION_ALGORITHM);
   SecretKey tmp = factory.generateSecret(new PBEKeySpec(password,
     salt, getPBKDFIterations(), AES_256_KEY_SIZE * 8));
   return new SecretKeySpec(tmp.getEncoded(), AES_NAME);
  } catch (GeneralSecurityException e) {
   throw new CryptorException(String.format(
     "Failed to generate key from password using %s.",
     KEY_DERIVATION_ALGORITHM), e);
  }

any help will be appreciated.

1

There are 1 answers

0
Duncan Jones On

Apologies for commenting and not realising you were talking about my software, JNCryptor.

You could take a look at a fork of the project, https://github.com/t0mm13b/AndroJNCryptor, which has attempted to make several Android-related improvements to the code. I believe your problem may be addressed in that code base.

As far as I know, there is no Android provider available that offers an algorithm named PBKDF2WithHmacSHA256. Quite frustrating!