// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException;

import javax.crypto.KDF;
import javax.crypto.SecretKey;
import javax.crypto.spec.HKDFParameterSpec;

public class KeyDeriv24 {
    public static void main(String[] args) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
        KDF hkdf256 = KDF.getInstance("HKDF-SHA256"); 
        SecretKey key = hkdf256.deriveKey("AES", HKDFParameterSpec.ofExtract()
                                                                  .addIKM("super secret password".getBytes())
                                                                  .addSalt(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 })
                                                                  .thenExpand(null, 32));
        System.out.println(key);
    }
}
