3

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.

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
George Thomas
  • 4,566
  • 5
  • 30
  • 65
  • The `NoSuchAlgorithmException: SecretKeyFactory PBKDF2WithHmacSHA256 implementation not found` message is pretty clear - `PBKDF2WithHmacSHA256` algorithm is not available on your device. – Oleg Estekhin Jun 30 '14 at 06:12
  • possible duplicate of [PBKDF2 with SHA256 on android](http://stackoverflow.com/questions/11628256/pbkdf2-with-sha256-on-android) – Oleg Estekhin Jun 30 '14 at 06:12
  • @ Oleg Estekhin thanks for your reply but that link is for PKCS5Padding what i am trying to do is with PKCS7Padding .... – George Thomas Jun 30 '14 at 06:33
  • Y this people are putting negative votes, i have researched a lot and it didn't help that y asked a question instead of answering,they put negative votes... – George Thomas Jun 30 '14 at 06:35
  • Do you think that whether PBKDF2WithHmacSHA256 factory is missing or not depends on whether you use PKCS5Padding or PKCS7Padding? Especially when these paddings are basically synonyms from the Java's point of view? – Oleg Estekhin Jun 30 '14 at 06:35
  • @ Oleg Estekhin: can we do PKCS7Padding implementation with that link, there is implementation using PKCS5Padding r8, so i thought it is the problem, that y i asked. How can we implement for PKCS7Padding,using the above link you provide – George Thomas Jun 30 '14 at 06:48
  • @George There is no difference between those two padding schemes. Strictly speaking one of them (PKCS #5) is only defined for 64-bit block sizes, but in practice they are identical and often PKCS#5 is the name used when in fact PKCS#7 is slightly more accurate. See http://en.wikipedia.org/wiki/Padding_%28cryptography%29#PKCS7. – Duncan Jones Jun 30 '14 at 09:31
  • @Duncan is that so thanks for your information,so what may be the issue.... – George Thomas Jun 30 '14 at 10:15

1 Answers1

2

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!

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254