Example #1
0
  @Test
  public void check() {
    String hashed = SCryptUtil.scrypt(passwd, N, r, p);

    assertTrue(SCryptUtil.check(passwd, hashed));
    assertFalse(SCryptUtil.check("s3cr3t", hashed));
  }
Example #2
0
  @Test
  public void check_WithSpecifiedSalt() {
    byte[] salt = new byte[16];
    Arrays.fill(salt, (byte) 1);

    String hashed = SCryptUtil.scrypt(passwd, salt, N, r, p);

    assertTrue(SCryptUtil.check(passwd, hashed));
    assertFalse(SCryptUtil.check("s3cr3t", hashed));
  }
Example #3
0
  @Test
  public void check() {
    String hashed = SCryptUtil.scrypt(passwd, 16384, 8, 1);

    assertTrue(SCryptUtil.check(passwd, hashed));
    assertFalse(SCryptUtil.check("s3cr3t", hashed));

    String hashed2 = SCryptUtil.scryptRuby(passwd, 16384, 8, 1);
    assertTrue(SCryptUtil.check(passwd, hashed2));
    assertFalse(SCryptUtil.check("s3cr3t", hashed2));

    // Test with an example from the Ruby scrypt project
    String preHashed =
        "400$8$36$78f4ae6983f76119$37ec6ce55a2b928dc56ff9a7d0cdafbd7dbde49d9282c38a40b1434e88f24cf5";
    assertTrue(SCryptUtil.check("my grand secret", preHashed));
  }
Example #4
0
  @Test
  public void format_0_rp_max() throws Exception {
    int N = 2;
    int r = 255;
    int p = 255;

    String hashed = SCryptUtil.scrypt(passwd, N, r, p);
    assertTrue(SCryptUtil.check(passwd, hashed));

    String[] parts = hashed.split("\\$");
    int params = Integer.valueOf(parts[2], 16);

    assertEquals(N, (int) Math.pow(2, params >>> 16 & 0xffff));
    assertEquals(r, params >> 8 & 0xff);
    assertEquals(p, params >> 0 & 0xff);
  }
Example #5
0
 @Test(expected = IllegalArgumentException.class)
 public void check_InvalidHashValueWrongVersion() {
   SCryptUtil.check(passwd, "$s1$PARAMS$SALT$KEY");
 }
Example #6
0
 @Test(expected = IllegalArgumentException.class)
 public void check_InvalidHashValueWrongNumberOfParts() {
   SCryptUtil.check(passwd, "$s0$PARAMS$SALT$KEY$EXTRA");
 }