@Test public void computeSha256() throws Exception { String P = "password"; byte[] S = "salt".getBytes(); int c = 1; int dkLen = 32; byte [] DK = Hex.decode("12 0f b6 cf fc f8 b3 2c\n" + "43 e7 22 52 56 c4 f8 37\n" + "a8 65 48 c9 2c cc 35 48\n" + "08 05 98 7c b7 0b e1 7b"); byte[] key = PBKDF2.derive(Sha256.class, P, S, c, dkLen); assertArrayEquals(DK, key); c = 2; DK = Hex.decode("ae 4d 0c 95 af 6b 46 d3\n" + " 2d 0a df f9 28 f0 6d d0\n" + " 2a 30 3f 8e f3 c2 51 df\n" + " d6 e2 d8 5a 95 47 4c 43"); c = 4096; DK = Hex.decode("c5 e4 78 d5 92 88 c8 41\n" + " aa 53 0d b6 84 5c 4c 8d\n" + " 96 28 93 a0 01 ce 4e 11\n" + " a4 96 38 73 aa 98 13 4a"); key = PBKDF2.derive(Sha256.class, P, S, c, dkLen); assertArrayEquals(DK, key); }
public static byte[] derive(Class<? extends Digest> hash, String password, byte[] salt, int c, int dkLen) { return new PBKDF2(hash, password, salt, c, dkLen).compute(); }
PBKDF2 { public static byte[] derive(Class<? extends Digest> hash, String password, byte[] salt, int c, int dkLen) { return new PBKDF2(hash, password, salt, c, dkLen).compute(); } }
PBKDF2 { public static byte[] derive(Class<? extends Digest> hash, String password, byte[] salt, int c, int dkLen) { return new PBKDF2(hash, password, salt, c, dkLen).compute(); } private  PBKDF2(Class<? extends Digest> hashClass,
                  String password,
                  byte[] salt,
                  int c,
                  int dkLen); }
PBKDF2 { public static byte[] derive(Class<? extends Digest> hash, String password, byte[] salt, int c, int dkLen) { return new PBKDF2(hash, password, salt, c, dkLen).compute(); } private  PBKDF2(Class<? extends Digest> hashClass,
                  String password,
                  byte[] salt,
                  int c,
                  int dkLen); static byte[] derive(Class<? extends Digest> hash, String password, byte[] salt, int c, int dkLen); }
PBKDF2 { public static byte[] derive(Class<? extends Digest> hash, String password, byte[] salt, int c, int dkLen) { return new PBKDF2(hash, password, salt, c, dkLen).compute(); } private  PBKDF2(Class<? extends Digest> hashClass,
                  String password,
                  byte[] salt,
                  int c,
                  int dkLen); static byte[] derive(Class<? extends Digest> hash, String password, byte[] salt, int c, int dkLen);  }