djekl
10/13/2016 - 8:07 AM

Does anybody know how to convert this to PHP correctly, and can provide a derived key in java, for comparison in PHP

Does anybody know how to convert this to PHP correctly, and can provide a derived key in java, for comparison in PHP

static byte[] deriveSP800108HmacSHA256Key(final int n, final byte[] array, final String s, final byte[] array2) {
    final ByteBuffer allocate = ByteBuffer.allocate(n);
    final ByteBuffer allocate2 = ByteBuffer.allocate(4);
    final Mac initializedHmacSha256Digester = Cryptography.getInitializedHmacSha256Digester(new SecretKeySpec(array, "HmacSHA256"));
    int n2 = 1;
    while (allocate.position() < n) {
        initializedHmacSha256Digester.reset();
        allocate2.clear();
        allocate2.putInt(n2);
        allocate2.rewind();
        initializedHmacSha256Digester.update(allocate2);
        initializedHmacSha256Digester.update(s.getBytes(Strings.Utf8Charset));
        initializedHmacSha256Digester.update((byte)0);
        initializedHmacSha256Digester.update(array2);
        allocate2.clear();
        allocate2.putInt(n * 8);
        allocate2.rewind();
        initializedHmacSha256Digester.update(allocate2);
        final byte[] doFinal = initializedHmacSha256Digester.doFinal();
        int n3;
        if ((n3 = doFinal.length) > allocate.remaining()) {
            n3 = allocate.remaining();
        }
        allocate.put(doFinal, 0, n3);
        ++n2;
    }
    return allocate.array();
}