This commit is contained in:
Xephi59
2015-07-20 02:41:14 +02:00
parent 663c4a48d1
commit 480db6816f
22 changed files with 98 additions and 129 deletions
@@ -14,7 +14,6 @@
package fr.xephi.authme.security.crypts;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
@@ -141,7 +140,7 @@ public class BCRYPT implements EncryptionMethod {
* @return the decoded value of x
*/
private static byte char64(char x) {
if ((int) x < 0 || (int) x > index_64.length)
if ((int) x > index_64.length)
return -1;
return index_64[(int) x];
}
@@ -14,7 +14,7 @@ public class CryptPBKDF2 implements EncryptionMethod {
PBKDF2Parameters params = new PBKDF2Parameters("HmacSHA256", "ASCII", salt.getBytes(), 10000);
PBKDF2Engine engine = new PBKDF2Engine(params);
return result + engine.deriveKey(password, 64).toString();
return result + String.valueOf(engine.deriveKey(password, 64));
}
@Override
@@ -60,9 +60,9 @@ import java.security.SecureRandom;
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* </p>
* <p>
* For Details, see <a
* href="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html"
* >http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html</a>.
* For Details, see
* <a href="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html" >http://www.
* gnu.org/licenses/old-licenses/lgpl-2.1.html</a>.
* </p>
*
* @see <a href="http://tools.ietf.org/html/rfc2898">RFC 2898</a>
@@ -319,8 +319,8 @@ public class PBKDF2Engine implements PBKDF2 {
* @throws IOException
* @throws NoSuchAlgorithmException
*/
public static void main(String[] args) throws IOException,
NoSuchAlgorithmException {
public static void main(String[] args)
throws IOException, NoSuchAlgorithmException {
String password = "password";
String candidate = null;
PBKDF2Formatter formatter = new PBKDF2HexFormatter();
@@ -341,7 +341,6 @@ public class PBKDF2Engine implements PBKDF2 {
PBKDF2Engine e = new PBKDF2Engine(p);
p.setDerivedKey(e.deriveKey(password));
candidate = formatter.toString(p);
System.out.println(candidate);
} else {
// Verification mode
PBKDF2Parameters p = new PBKDF2Parameters();
@@ -352,7 +351,6 @@ public class PBKDF2Engine implements PBKDF2 {
}
PBKDF2Engine e = new PBKDF2Engine(p);
boolean verifyOK = e.verifyKey(password);
System.out.println(verifyOK ? "OK" : "FAIL");
System.exit(verifyOK ? 0 : 1);
}
}