3 replies Latest Post - ‏2014-03-18T21:02:13Z by mcpin
549 Posts

Pinned topic OutOfMemoryError using PBKDF2WithHmacSHA1

‏2011-07-08T15:35:37Z |

Our app runs on AIX, Solaris, and Windows. We have implemented a salted hashed password system using a SecretKeyFactory with PBKDF2WithHmacSHA1. When running on the AIX J9 JRE, we get an OutOfMemoryError that is caused by the use of PBKDF2WithHmacSHA1. We're using the latest IBM J9 JRE for AIX: 6.0 SR9 FP1. My simplified test case throws an OutOfMemoryError after about 3600 iterations. This does not occur on Sun's (Oracle's) Solaris or Windows JVMs (both HotSpot).

package cryptotest;

import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;

public class CryptoTest {
public static void main(String[] args) {

char [] passwordChars = "This is a test".toCharArray();
byte [] randomSaltBytes = {-79, 63, -46, 34, -84, -81, -82, -60, 100, 28, -15, 92, -76, 53, 84, 10};

for (int i = 1; i <= 10000; i++) {
try {
SecretKeyFactory skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
PBEKeySpec ks = new PBEKeySpec(passwordChars, randomSaltBytes, 5000, 256);
catch (Exception e) {

if ((i % 100) == 0) { System.out.println(" Completed: " + i); }


I realize that running the test case in a tight loop is not the best scenario for the GC, but the OOME occurs after about 3.5 hours in our full application. So the GC should have had plenty of time for reclamation. Plus the fact that the exact same test case runs to completion on Solaris and Windows.

All JVM params are the defaults.

None of the other SecretKeyFactory algorithms cause the OOME.

I have looked into using Bouncy Castle as the crypto provider, but they apparently do not yet support PBKDF2WithHmacSHA1.

IBM HeapAnalyzer shows the following as the leak suspect:

TotalSize (TotalSize/HeapSize%) ObjectSize NumberOfChildObject(2,227) ObjectName Address
532,853,264 (99%) 32 12 class javax/crypto/b 0xb01230d0
532,818,040 (99%) 40 1 java/util/IdentityHashMap 0xb0120948
532,818,000 (99%) 57,360 7,260 array of java/lang/Object 0xc77256c8
149,104 (0%) 120 9 com/ibm/crypto/provider/IBMJCE 0xb3dbf060
149,104 (0%) 120 9 com/ibm/crypto/provider/IBMJCE 0xb141c530
149,104 (0%) 120 9 com/ibm/crypto/provider/IBMJCE 0xb05c9958

Is there a JVM setting necessary, or something else I am missing?

Many thanks in advance,

Updated on 2012-10-09T16:03:31Z at 2012-10-09T16:03:31Z by Ramos
  • SystemAdmin
    549 Posts

    Re: OutOfMemoryError using PBKDF2WithHmacSHA1

    ‏2011-08-29T20:04:54Z  in response to SystemAdmin
    For the benefit of anyone else encountering this issue, IBM has identified it as an open issue in their JCE, and will be fixed in the next release:
    • Ramos
      1 Post

      Re: OutOfMemoryError using PBKDF2WithHmacSHA1

      ‏2012-10-09T16:03:31Z  in response to SystemAdmin
      I came across the same issue. Switching from ibm-java-x86_64-60 to ibm-java-x86_64-70 solved it.
      • mcpin
        1 Post

        Re: OutOfMemoryError using PBKDF2WithHmacSHA1

        ‏2014-03-18T21:02:13Z  in response to Ramos

        I have the same issue ("OutOfMemory") , but using IAIK provider on ibm-java-x86_64_60 SR10 FP1. Heap is exhausted by objects owned by IdentityHashMap,  whose ancestor is javax.crypto.b ... but I cannot  switch to ibm-java-x86_64-70 ....

        Many Thanks,

        María Cecilia