@Test public void pbkdf2() throws NigoriCryptographyException { for (PbkdfTestCase testCase : pbkdfTestCases) { byte[] answer = RealKeyManager.pbkdf2(testCase.password, testCase.salt, testCase.rounds, testCase.outputBytes); assertArrayEquals(testCase.answer, answer); } }
protected static byte[] pbkdf2(byte[] password, byte[] salt, int rounds, int outputByteCount) throws NigoriCryptographyException { char[] charPassword = new char[password.length]; for (int i = 0; i < charPassword.length; i++) { if (password[i] >= 0) { charPassword[i] = (char) password[i]; } else { charPassword[i] = (char) (password[i] + 256); } } try { SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); KeySpec spec = new PBEKeySpec(charPassword, salt, rounds, 8 * outputByteCount); return factory.generateSecret(spec).getEncoded(); } catch (NoSuchAlgorithmException e) { throw new NigoriCryptographyException(e); } catch (InvalidKeySpecException e) { throw new NigoriCryptographyException(e); } }
RealKeyManager implements KeyManager { protected static byte[] pbkdf2(byte[] password, byte[] salt, int rounds, int outputByteCount) throws NigoriCryptographyException { char[] charPassword = new char[password.length]; for (int i = 0; i < charPassword.length; i++) { if (password[i] >= 0) { charPassword[i] = (char) password[i]; } else { charPassword[i] = (char) (password[i] + 256); } } try { SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); KeySpec spec = new PBEKeySpec(charPassword, salt, rounds, 8 * outputByteCount); return factory.generateSecret(spec).getEncoded(); } catch (NoSuchAlgorithmException e) { throw new NigoriCryptographyException(e); } catch (InvalidKeySpecException e) { throw new NigoriCryptographyException(e); } } }
RealKeyManager implements KeyManager { protected static byte[] pbkdf2(byte[] password, byte[] salt, int rounds, int outputByteCount) throws NigoriCryptographyException { char[] charPassword = new char[password.length]; for (int i = 0; i < charPassword.length; i++) { if (password[i] >= 0) { charPassword[i] = (char) password[i]; } else { charPassword[i] = (char) (password[i] + 256); } } try { SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); KeySpec spec = new PBEKeySpec(charPassword, salt, rounds, 8 * outputByteCount); return factory.generateSecret(spec).getEncoded(); } catch (NoSuchAlgorithmException e) { throw new NigoriCryptographyException(e); } catch (InvalidKeySpecException e) { throw new NigoriCryptographyException(e); } } RealKeyManager(String serverName, byte[] username, byte[] password);  RealKeyManager(String serverName); }
RealKeyManager implements KeyManager { protected static byte[] pbkdf2(byte[] password, byte[] salt, int rounds, int outputByteCount) throws NigoriCryptographyException { char[] charPassword = new char[password.length]; for (int i = 0; i < charPassword.length; i++) { if (password[i] >= 0) { charPassword[i] = (char) password[i]; } else { charPassword[i] = (char) (password[i] + 256); } } try { SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); KeySpec spec = new PBEKeySpec(charPassword, salt, rounds, 8 * outputByteCount); return factory.generateSecret(spec).getEncoded(); } catch (NoSuchAlgorithmException e) { throw new NigoriCryptographyException(e); } catch (InvalidKeySpecException e) { throw new NigoriCryptographyException(e); } } RealKeyManager(String serverName, byte[] username, byte[] password);  RealKeyManager(String serverName); @Override byte[] getUsername(); @Override byte[] getPassword(); @Override String getServerName(); @Override byte[] decrypt(byte[] ciphertext); @Override byte[] decrypt(byte[] encryptionKey, byte[] ciphertext); @Override byte[] encrypt(byte[] plaintext); @Override byte[] encrypt(byte[] key, byte[] plaintext); @Override byte[] encryptDeterministically(byte[] plaintext); @Override byte[] encryptDeterministically(byte[] key, byte[] plaintext); @Override DSASign signer(); void destroy(); @Override void finalize(); }
RealKeyManager implements KeyManager { protected static byte[] pbkdf2(byte[] password, byte[] salt, int rounds, int outputByteCount) throws NigoriCryptographyException { char[] charPassword = new char[password.length]; for (int i = 0; i < charPassword.length; i++) { if (password[i] >= 0) { charPassword[i] = (char) password[i]; } else { charPassword[i] = (char) (password[i] + 256); } } try { SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); KeySpec spec = new PBEKeySpec(charPassword, salt, rounds, 8 * outputByteCount); return factory.generateSecret(spec).getEncoded(); } catch (NoSuchAlgorithmException e) { throw new NigoriCryptographyException(e); } catch (InvalidKeySpecException e) { throw new NigoriCryptographyException(e); } } RealKeyManager(String serverName, byte[] username, byte[] password);  RealKeyManager(String serverName); @Override byte[] getUsername(); @Override byte[] getPassword(); @Override String getServerName(); @Override byte[] decrypt(byte[] ciphertext); @Override byte[] decrypt(byte[] encryptionKey, byte[] ciphertext); @Override byte[] encrypt(byte[] plaintext); @Override byte[] encrypt(byte[] key, byte[] plaintext); @Override byte[] encryptDeterministically(byte[] plaintext); @Override byte[] encryptDeterministically(byte[] key, byte[] plaintext); @Override DSASign signer(); void destroy(); @Override void finalize();  }