Beispiel #1
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));
  }
Beispiel #2
0
  @Test
  public void scryptRuby() {
    int N = 1024;
    int r = 8;
    int p = 1;

    String hashed = SCryptUtil.scryptRuby(passwd, N, r, p);
    String[] parts = hashed.split("\\$");

    assertEquals(5, parts.length);
    try {
      assertEquals(8, Hex.decodeHex(parts[3].toCharArray()).length);
      assertEquals(32, Hex.decodeHex(parts[4].toCharArray()).length);
    } catch (DecoderException e) {
      fail("There was an exception decoding the hashed value: \n" + e.getMessage());
    }
    assertEquals(N, Integer.parseInt(parts[0], 16));
    assertEquals(r, Integer.parseInt(parts[1], 16));
    assertEquals(p, Integer.parseInt(parts[2], 16));
  }