Examples of PBKDF2


Examples of com.calclab.emite.base.crypto.PBKDF2

    final String clm = "c=" + Base64.toBase64(gs2hdr.getBytes()) + ",r=" + snonce;
    return (cfm + "," + sfm + "," + clm).getBytes();
  }

  private final byte[] clientProof() {
    final byte[] saltedPassword = new PBKDF2().doKey(credentials.getPassword().getBytes(), salt, icount);
    final byte[] clientKey = new HMac().doMac(saltedPassword, "Client Key".getBytes());
    final byte[] storedKey = new SHA1Digest().doHash(clientKey);
    final byte[] clientSignature = new HMac().doMac(storedKey, authMessage());
    return XOR(clientKey, clientSignature);
  }
View Full Code Here

Examples of com.calclab.emite.base.crypto.PBKDF2

    final byte[] clientSignature = new HMac().doMac(storedKey, authMessage());
    return XOR(clientKey, clientSignature);
  }

  private final byte[] serverSignature() {
    final byte[] saltedPassword = new PBKDF2().doKey(credentials.getPassword().getBytes(), salt, icount);
    final byte[] serverKey = new HMac().doMac(saltedPassword, "Server Key".getBytes());
    return new HMac().doMac(serverKey, authMessage());
  }
View Full Code Here

Examples of gnu.javax.crypto.prng.PBKDF2

  public void test(TestHarness harness)
  {
    try
      {
        harness.checkPoint("PBKDF2");
        PBKDF2 kdf = new PBKDF2(MacFactory.getInstance("HMAC-SHA1"));
        HashMap attr = new HashMap();
        byte[] dk = new byte[32];
        byte[] edk;
        byte[] salt;
        char[] password;

        // Iteration count = 1
        // Pass phrase = "password"
        // Salt = "ATHENA.MIT.EDUraeburn"
        // 256-bit PBKDF2 output:
        //   cd ed b5 28 1b b2 f8 01 56 5a 11 22 b2 56 35 15
        //   0a d1 f7 a0 4b b9 f3 a3 33 ec c0 e2 e1 f7 08 37
        edk = Util.toBytesFromString(
            "cdedb5281bb2f801565a1122b25635150ad1f7a04bb9f3a333ecc0e2e1f70837");
        password = "password".toCharArray();
        salt = "ATHENA.MIT.EDUraeburn".getBytes();
        attr.put(IPBE.ITERATION_COUNT, new Integer(1));
        attr.put(IPBE.PASSWORD, password);
        attr.put(IPBE.SALT, salt);
        try
          {
            kdf.init(attr);
            kdf.nextBytes(dk, 0, dk.length);
            harness.check(Arrays.equals(dk, edk));
          }
        catch (Exception x)
          {
            harness.debug(x);
            harness.fail(x.toString());
          }

        // Iteration count = 2
        // Pass phrase = "password"
        // Salt="ATHENA.MIT.EDUraeburn"
        // 256-bit PBKDF2 output:
        //   01 db ee 7f 4a 9e 24 3e 98 8b 62 c7 3c da 93 5d
        //   a0 53 78 b9 32 44 ec 8f 48 a9 9e 61 ad 79 9d 86
        edk = Util.toBytesFromString(
            "01dbee7f4a9e243e988b62c73cda935da05378b93244ec8f48a99e61ad799d86");
        attr.put(IPBE.ITERATION_COUNT, new Integer(2));
        try
          {
            kdf.init(attr);
            kdf.nextBytes(dk, 0, dk.length);
            harness.check(Arrays.equals(dk, edk));
          }
        catch (Exception x)
          {
            harness.debug(x);
            harness.fail(x.toString());
          }

        // Iteration count = 1200
        // Pass phrase = "password"
        // Salt = "ATHENA.MIT.EDUraeburn"
        // 256-bit PBKDF2 output:
        //   5c 08 eb 61 fd f7 1e 4e 4e c3 cf 6b a1 f5 51 2b
        //   a7 e5 2d db c5 e5 14 2f 70 8a 31 e2 e6 2b 1e 13
        edk = Util.toBytesFromString(
            "5c08eb61fdf71e4e4ec3cf6ba1f5512ba7e52ddbc5e5142f708a31e2e62b1e13");
        attr.put(IPBE.ITERATION_COUNT, new Integer(1200));
        attr.put(IPBE.PASSWORD, password);
        attr.put(IPBE.SALT, salt);
        try
          {
            kdf.init(attr);
            kdf.nextBytes(dk, 0, dk.length);
            harness.check(Arrays.equals(dk, edk));
          }
        catch (Exception x)
          {
            harness.debug(x);
            harness.fail(x.toString());
          }

        // Iteration count = 5
        // Pass phrase = "password"
        // Salt=0x1234567878563412
        // 256-bit PBKDF2 output:
        //   d1 da a7 86 15 f2 87 e6 a1 c8 b1 20 d7 06 2a 49
        //
        edk = Util.toBytesFromString(
            "d1daa78615f287e6a1c8b120d7062a493f98d203e6be49a6adf4fa574b6e64ee");
        salt = Util.toBytesFromString("1234567878563412");
        attr.put(IPBE.ITERATION_COUNT, new Integer(5));
        attr.put(IPBE.PASSWORD, password);
        attr.put(IPBE.SALT, salt);
        try
          {
            kdf.init(attr);
            kdf.nextBytes(dk, 0, dk.length);
            harness.check(Arrays.equals(dk, edk));
          }
        catch (Exception x)
          {
            harness.debug(x);
            harness.fail(x.toString());
          }

        // Iteration count = 1200
        // Pass phrase = (64 characters)
        // "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
        // Salt="pass phrase equals block size"
        // 256-bit PBKDF2 output:
        //   13 9c 30 c0 96 6b c3 2b a5 5f db f2 12 53 0a c9
        //   c5 ec 59 f1 a4 52 f5 cc 9a d9 40 fe a0 59 8e d1
        edk = Util.toBytesFromString(
            "139c30c0966bc32ba55fdbf212530ac9c5ec59f1a452f5cc9ad940fea0598ed1");
        password =
            "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
            .toCharArray();
        salt = "pass phrase equals block size".getBytes();
        attr.put(IPBE.ITERATION_COUNT, new Integer(1200));
        attr.put(IPBE.PASSWORD, password);
        attr.put(IPBE.SALT, salt);
        try
          {
            kdf.init(attr);
            kdf.nextBytes(dk, 0, dk.length);
            harness.check(Arrays.equals(dk, edk));
          }
        catch (Exception x)
          {
            harness.debug(x);
            harness.fail(x.toString());
          }

        // Iteration count = 1200
        // Pass phrase = (65 characters)
        // "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
        // Salt = "pass phrase exceeds block size"
        // 256-bit PBKDF2 output:
        //   9c ca d6 d4 68 77 0c d5 1b 10 e6 a6 87 21 be 61
        //   1a 8b 4d 28 26 01 db 3b 36 be 92 46 91 5e c8 2a
        edk = Util.toBytesFromString(
            "9ccad6d468770cd51b10e6a68721be611a8b4d282601db3b36be9246915ec82a");
        password =
            "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
            .toCharArray();
        salt = "pass phrase exceeds block size".getBytes();
        attr.put(IPBE.ITERATION_COUNT, new Integer(1200));
        attr.put(IPBE.PASSWORD, password);
        attr.put(IPBE.SALT, salt);
        try
          {
            kdf.init(attr);
            kdf.nextBytes(dk, 0, dk.length);
            harness.check(Arrays.equals(dk, edk));
          }
        catch (Exception x)
          {
            harness.debug(x);
View Full Code Here

Examples of org.jboss.aerogear.crypto.password.Pbkdf2

    }

    @Test
    public void testAcceptPasswordBasedPrivateKey() throws Exception {
        try {
            Pbkdf2 pbkdf2 = AeroGearCrypto.pbkdf2();
            byte[] rawPassword = pbkdf2.encrypt(PASSWORD);
            new CryptoBox(new PrivateKey(rawPassword));
        } catch (Exception e) {
            fail("CryptoBox should accept key pairs");
        }
    }
View Full Code Here

Examples of org.jboss.aerogear.crypto.password.Pbkdf2

        assertEquals("decrypted message should equals the message", RAW.encode(message), BOX_STRING_MESSAGE);
    }

    @Test
    public void testPasswordBasedKeyDecryptRawBytes() throws Exception {
        Pbkdf2 pbkdf2 = AeroGearCrypto.pbkdf2();
        byte[] rawPassword = pbkdf2.encrypt(PASSWORD);
        PrivateKey privateKey = new PrivateKey(rawPassword);

        CryptoBox cryptoBox = new CryptoBox(privateKey);
        byte[] IV = HEX.decode(CRYPTOBOX_IV);
        byte[] expectedMessage = HEX.decode(CRYPTOBOX_MESSAGE);
View Full Code Here

Examples of org.jboss.aerogear.crypto.password.Pbkdf2

public class HmacTest {

    @Test
    public void testSHA1HmacDigest() throws Exception {
        Pbkdf2 pbkdf2 = AeroGearCrypto.pbkdf2();
        byte[] salt = HMAC_STRING_SALT.getBytes();
        int iterations = 100000;
        SecretKey secretKey = pbkdf2.generateSecretKey(PASSWORD, salt, iterations);
        Hmac hmac = new Hmac("HmacSha1", secretKey);
        assertEquals(HMAC_STRING_DIGEST_SHA1, hmac.digest(HMAC_STRING_MESSAGE.getBytes()));
    }
View Full Code Here

Examples of org.jboss.aerogear.crypto.password.Pbkdf2

        assertEquals(HMAC_STRING_DIGEST_SHA1, hmac.digest(HMAC_STRING_MESSAGE.getBytes()));
    }

    @Test
    public void testSHA256HmacDigest() throws Exception {
        Pbkdf2 pbkdf2 = AeroGearCrypto.pbkdf2();
        byte[] salt = HMAC_STRING_SALT.getBytes();
        int iterations = 100000;
        SecretKey secretKey = pbkdf2.generateSecretKey(PASSWORD, salt, iterations);
        Hmac hmac = new Hmac(secretKey);
        assertEquals(HMAC_STRING_DIGEST_SHA256, hmac.digest(HMAC_STRING_MESSAGE.getBytes()));
    }
View Full Code Here

Examples of org.jboss.aerogear.crypto.password.Pbkdf2

    }


    @Test
    public void testSHA512HmacDigest() throws Exception {
        Pbkdf2 pbkdf2 = AeroGearCrypto.pbkdf2();
        byte[] salt = HMAC_STRING_SALT.getBytes();
        int iterations = 100000;
        SecretKey secretKey = pbkdf2.generateSecretKey(PASSWORD, salt, iterations);
        Hmac hmac = new Hmac("HmacSha512", secretKey);
        assertEquals(HMAC_STRING_DIGEST_SHA512, hmac.digest(HMAC_STRING_MESSAGE.getBytes()));
    }
View Full Code Here

Examples of org.jboss.aerogear.crypto.password.Pbkdf2

    }


    @Test(expected = RuntimeException.class)
    public void testAlgorithmNotFound() throws Exception {
        Pbkdf2 pbkdf2 = AeroGearCrypto.pbkdf2();
        byte[] salt = HMAC_STRING_SALT.getBytes();
        int iterations = 100000;
        SecretKey secretKey = pbkdf2.generateSecretKey(PASSWORD, salt, iterations);
        new Hmac("InvalidAlgorithm", secretKey);
    }
View Full Code Here

Examples of org.jboss.aerogear.crypto.password.Pbkdf2

    }

    @Test
    public void testAcceptsPasswordBasedValidKey() throws Exception {
        try {
            Pbkdf2 pbkdf2 = AeroGearCrypto.pbkdf2();
            byte[] rawPassword = pbkdf2.encrypt(PASSWORD);
            new PrivateKey(rawPassword);
        } catch (Exception e) {
            e.printStackTrace();
            fail("Should return a valid key size");
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.