Prepare the project for javadocs

This commit is contained in:
Gabriele C
2015-11-21 01:27:06 +01:00
parent adcd70b91d
commit 118c79401a
168 changed files with 4375 additions and 422 deletions
@@ -92,9 +92,9 @@ public class BCRYPT implements EncryptionMethod {
*
* @param d the byte array to encode
* @param len the number of bytes to encode
* @return base64-encoded string
* @throws IllegalArgumentException if the length is invalid
*/
* @return base64-encoded string * @throws IllegalArgumentException if the length is invalid */
private static String encode_base64(byte d[], int len)
throws IllegalArgumentException {
int off = 0;
@@ -133,8 +133,8 @@ public class BCRYPT implements EncryptionMethod {
* range-checking againt conversion table
*
* @param x the base64-encoded value
* @return the decoded value of x
*/
* @return the decoded value of x */
private static byte char64(char x) {
if ((int) x > index_64.length)
return -1;
@@ -148,9 +148,9 @@ public class BCRYPT implements EncryptionMethod {
*
* @param s the string to decode
* @param maxolen the maximum number of bytes to decode
* @return an array containing the decoded bytes
* @throws IllegalArgumentException if maxolen is invalid
*/
* @return an array containing the decoded bytes * @throws IllegalArgumentException if maxolen is invalid */
private static byte[] decode_base64(String s, int maxolen)
throws IllegalArgumentException {
StringBuffer rs = new StringBuffer();
@@ -227,8 +227,8 @@ public class BCRYPT implements EncryptionMethod {
* @param data the string to extract the data from
* @param offp a "pointer" (as a one-entry array) to the current offset into
* data
* @return the next word of material from data
*/
* @return the next word of material from data */
private static int streamtoword(byte data[], int offp[]) {
int i;
int word = 0;
@@ -319,8 +319,8 @@ public class BCRYPT implements EncryptionMethod {
* @param salt the binary salt to hash with the password
* @param log_rounds the binary logarithm of the number of rounds of hashing to
* apply
* @return an array containing the binary hashed password
*/
* @return an array containing the binary hashed password */
private byte[] crypt_raw(byte password[], byte salt[], int log_rounds) {
int rounds, i, j;
int cdata[] = bf_crypt_ciphertext.clone();
@@ -360,8 +360,8 @@ public class BCRYPT implements EncryptionMethod {
*
* @param password the password to hash
* @param salt the salt to hash with (perhaps generated using BCrypt.gensalt)
* @return the hashed password
*/
* @return the hashed password */
public static String hashpw(String password, String salt) {
BCRYPT B;
String real_salt;
@@ -417,8 +417,8 @@ public class BCRYPT implements EncryptionMethod {
* @param log_rounds the log2 of the number of rounds of hashing to apply - the
* work factor therefore increases as 2**log_rounds.
* @param random an instance of SecureRandom to use
* @return an encoded salt value
*/
* @return an encoded salt value */
public static String gensalt(int log_rounds, SecureRandom random) {
StringBuffer rs = new StringBuffer();
byte rnd[] = new byte[BCRYPT_SALT_LEN];
@@ -439,8 +439,8 @@ public class BCRYPT implements EncryptionMethod {
*
* @param log_rounds the log2 of the number of rounds of hashing to apply - the
* work factor therefore increases as 2**log_rounds.
* @return an encoded salt value
*/
* @return an encoded salt value */
public static String gensalt(int log_rounds) {
return gensalt(log_rounds, new SecureRandom());
}
@@ -449,8 +449,8 @@ public class BCRYPT implements EncryptionMethod {
* Generate a salt for use with the BCrypt.hashpw() method, selecting a
* reasonable default for the number of hashing rounds to apply
*
* @return an encoded salt value
*/
* @return an encoded salt value */
public static String gensalt() {
return gensalt(GENSALT_DEFAULT_LOG2_ROUNDS);
}
@@ -460,8 +460,8 @@ public class BCRYPT implements EncryptionMethod {
*
* @param plaintext the plaintext password to verify
* @param hashed the previously-hashed password
* @return true if the passwords match, false otherwise
*/
* @return true if the passwords match, false otherwise */
public static boolean checkpw(String plaintext, String hashed) {
return (hashed.compareTo(hashpw(plaintext, hashed)) == 0);
}
@@ -473,7 +473,8 @@ public class BCRYPT implements EncryptionMethod {
* @param text plaintext or hashed text
* @param hashed the previously-hashed password
* @param rounds number of rounds to hash the password
* @return
* @return boolean
*/
public static boolean checkpw(String text, String hashed, int rounds) {
boolean matched = false;
@@ -493,18 +494,42 @@ public class BCRYPT implements EncryptionMethod {
return matched;
}
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
* @return String
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
*/
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return hashpw(password, salt);
}
/**
* Method comparePassword.
* @param hash String
* @param password String
* @param playerName String
* @return boolean
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return checkpw(password, hash);
}
/**
* Method getDoubleHash.
* @param text String
* @param salt String
* @return String
*/
public static String getDoubleHash(String text, String salt) {
String hash = hashpw(text, salt);
return hashpw(text, hash);
@@ -2,8 +2,19 @@ package fr.xephi.authme.security.crypts;
import java.security.NoSuchAlgorithmException;
/**
*/
public class BCRYPT2Y implements EncryptionMethod {
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
* @return String
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
*/
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
@@ -12,6 +23,15 @@ public class BCRYPT2Y implements EncryptionMethod {
return (BCRYPT.hashpw(password, salt));
}
/**
* Method comparePassword.
* @param hash String
* @param password String
* @param playerName String
* @return boolean
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
@@ -4,11 +4,22 @@ import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
*/
public class CRAZYCRYPT1 implements EncryptionMethod {
protected final Charset charset = Charset.forName("UTF-8");
private static final char[] CRYPTCHARS = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
* @return String
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
*/
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
@@ -21,13 +32,27 @@ public class CRAZYCRYPT1 implements EncryptionMethod {
return null;
}
}
/**
* Method comparePassword.
* @param hash String
* @param password String
* @param playerName String
* @return boolean
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return hash.equals(getHash(password, null, playerName));
}
/**
* Method byteArrayToHexString.
* @param args byte[]
* @return String
*/
public static String byteArrayToHexString(final byte... args) {
final char[] chars = new char[args.length * 2];
for (int i = 0; i < args.length; i++) {
@@ -5,8 +5,19 @@ import java.security.NoSuchAlgorithmException;
import fr.xephi.authme.security.pbkdf2.PBKDF2Engine;
import fr.xephi.authme.security.pbkdf2.PBKDF2Parameters;
/**
*/
public class CryptPBKDF2 implements EncryptionMethod {
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
* @return String
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
*/
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
@@ -17,6 +28,15 @@ public class CryptPBKDF2 implements EncryptionMethod {
return result + String.valueOf(engine.deriveKey(password, 64));
}
/**
* Method comparePassword.
* @param hash String
* @param password String
* @param playerName String
* @return boolean
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
@@ -7,8 +7,19 @@ import javax.xml.bind.DatatypeConverter;
import fr.xephi.authme.security.pbkdf2.PBKDF2Engine;
import fr.xephi.authme.security.pbkdf2.PBKDF2Parameters;
/**
*/
public class CryptPBKDF2Django implements EncryptionMethod {
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
* @return String
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
*/
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
@@ -19,6 +30,15 @@ public class CryptPBKDF2Django implements EncryptionMethod {
return result + String.valueOf(DatatypeConverter.printBase64Binary(engine.deriveKey(password, 32)));
}
/**
* Method comparePassword.
* @param hash String
* @param password String
* @param playerName String
* @return boolean
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
@@ -4,20 +4,46 @@ import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
*/
public class DOUBLEMD5 implements EncryptionMethod {
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
* @return String
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
*/
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getMD5(getMD5(password));
}
/**
* Method comparePassword.
* @param hash String
* @param password String
* @param playerName String
* @return boolean
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return hash.equals(getHash(password, "", ""));
}
/**
* Method getMD5.
* @param message String
* @return String
* @throws NoSuchAlgorithmException
*/
private static String getMD5(String message)
throws NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("MD5");
@@ -13,6 +13,8 @@ import java.security.NoSuchAlgorithmException;
* <p>
* The comparePassword is called when we need to match password (/login usually)
* </p>
* @author Gabriele
* @version $Revision: 1.0 $
*/
public interface EncryptionMethod {
@@ -21,9 +23,10 @@ public interface EncryptionMethod {
* @param salt
* (can be an other data like playerName;salt , playerName,
* etc... for customs methods)
* @return Hashing password
* @throws NoSuchAlgorithmException
*/
* @param name String
* @return Hashing password * @throws NoSuchAlgorithmException */
String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException;
@@ -31,9 +34,9 @@ public interface EncryptionMethod {
* @param hash
* @param password
* @param playerName
* @return true if password match, false else
* @throws NoSuchAlgorithmException
*/
* @return true if password match, false else * @throws NoSuchAlgorithmException */
boolean comparePassword(String hash, String password, String playerName)
throws NoSuchAlgorithmException;
@@ -6,14 +6,34 @@ import java.security.NoSuchAlgorithmException;
import fr.xephi.authme.AuthMe;
/**
*/
public class IPB3 implements EncryptionMethod {
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
* @return String
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
*/
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getMD5(getMD5(salt) + getMD5(password));
}
/**
* Method comparePassword.
* @param hash String
* @param password String
* @param playerName String
* @return boolean
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
@@ -21,6 +41,12 @@ public class IPB3 implements EncryptionMethod {
return hash.equals(getHash(password, salt, playerName));
}
/**
* Method getMD5.
* @param message String
* @return String
* @throws NoSuchAlgorithmException
*/
private static String getMD5(String message)
throws NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("MD5");
@@ -4,14 +4,34 @@ import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
*/
public class JOOMLA implements EncryptionMethod {
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
* @return String
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
*/
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getMD5(password + salt) + ":" + salt;
}
/**
* Method comparePassword.
* @param hash String
* @param password String
* @param playerName String
* @return boolean
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
@@ -19,6 +39,12 @@ public class JOOMLA implements EncryptionMethod {
return hash.equals(getMD5(password + salt) + ":" + salt);
}
/**
* Method getMD5.
* @param message String
* @return String
* @throws NoSuchAlgorithmException
*/
private static String getMD5(String message)
throws NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("MD5");
@@ -4,20 +4,46 @@ import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
*/
public class MD5 implements EncryptionMethod {
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
* @return String
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
*/
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getMD5(password);
}
/**
* Method comparePassword.
* @param hash String
* @param password String
* @param playerName String
* @return boolean
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return hash.equals(getHash(password, "", ""));
}
/**
* Method getMD5.
* @param message String
* @return String
* @throws NoSuchAlgorithmException
*/
private static String getMD5(String message)
throws NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("MD5");
@@ -4,14 +4,34 @@ import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
*/
public class MD5VB implements EncryptionMethod {
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
* @return String
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
*/
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return "$MD5vb$" + salt + "$" + getMD5(getMD5(password) + salt);
}
/**
* Method comparePassword.
* @param hash String
* @param password String
* @param playerName String
* @return boolean
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
@@ -19,6 +39,12 @@ public class MD5VB implements EncryptionMethod {
return hash.equals(getHash(password, line[2], ""));
}
/**
* Method getMD5.
* @param message String
* @return String
* @throws NoSuchAlgorithmException
*/
private static String getMD5(String message)
throws NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("MD5");
@@ -6,14 +6,34 @@ import java.security.NoSuchAlgorithmException;
import fr.xephi.authme.AuthMe;
/**
*/
public class MYBB implements EncryptionMethod {
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
* @return String
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
*/
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getMD5(getMD5(salt) + getMD5(password));
}
/**
* Method comparePassword.
* @param hash String
* @param password String
* @param playerName String
* @return boolean
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
@@ -21,6 +41,12 @@ public class MYBB implements EncryptionMethod {
return hash.equals(getHash(password, salt, playerName));
}
/**
* Method getMD5.
* @param message String
* @return String
* @throws NoSuchAlgorithmException
*/
private static String getMD5(String message)
throws NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("MD5");
@@ -11,11 +11,18 @@ import java.security.NoSuchAlgorithmException;
/**
* @author stefano
* @version $Revision: 1.0 $
*/
public class PHPBB implements EncryptionMethod {
private String itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
/**
* Method phpbb_hash.
* @param password String
* @param salt String
* @return String
*/
public String phpbb_hash(String password, String salt) {
String random_state = salt;
StringBuilder random = new StringBuilder();
@@ -31,10 +38,23 @@ public class PHPBB implements EncryptionMethod {
return md5(password);
}
/**
* Method _hash_gensalt_private.
* @param input String
* @param itoa64 String
* @return String
*/
private String _hash_gensalt_private(String input, String itoa64) {
return _hash_gensalt_private(input, itoa64, 6);
}
/**
* Method _hash_gensalt_private.
* @param input String
* @param itoa64 String
* @param iteration_count_log2 int
* @return String
*/
private String _hash_gensalt_private(String input, String itoa64,
int iteration_count_log2) {
if (iteration_count_log2 < 4 || iteration_count_log2 > 31) {
@@ -48,6 +68,9 @@ public class PHPBB implements EncryptionMethod {
/**
* Encode hash
* @param input String
* @param count int
* @return String
*/
private String _hash_encode64(String input, int count) {
StringBuilder output = new StringBuilder();
@@ -70,6 +93,12 @@ public class PHPBB implements EncryptionMethod {
return output.toString();
}
/**
* Method _hash_crypt_private.
* @param password String
* @param setting String
* @return String
*/
String _hash_crypt_private(String password, String setting) {
String output = "*";
if (!setting.substring(0, 3).equals("$H$"))
@@ -91,12 +120,23 @@ public class PHPBB implements EncryptionMethod {
return output;
}
/**
* Method phpbb_check_hash.
* @param password String
* @param hash String
* @return boolean
*/
public boolean phpbb_check_hash(String password, String hash) {
if (hash.length() == 34)
return _hash_crypt_private(password, hash).equals(hash);
else return md5(password).equals(hash);
}
/**
* Method md5.
* @param data String
* @return String
*/
public static String md5(String data) {
try {
byte[] bytes = data.getBytes("ISO-8859-1");
@@ -108,6 +148,11 @@ public class PHPBB implements EncryptionMethod {
}
}
/**
* Method hexToInt.
* @param ch char
* @return int
*/
static int hexToInt(char ch) {
if (ch >= '0' && ch <= '9')
return ch - '0';
@@ -117,6 +162,11 @@ public class PHPBB implements EncryptionMethod {
throw new IllegalArgumentException("Not a hex character: " + ch);
}
/**
* Method bytes2hex.
* @param bytes byte[]
* @return String
*/
private static String bytes2hex(byte[] bytes) {
StringBuilder r = new StringBuilder(32);
for (byte b : bytes) {
@@ -128,6 +178,11 @@ public class PHPBB implements EncryptionMethod {
return r.toString();
}
/**
* Method pack.
* @param hex String
* @return String
*/
static String pack(String hex) {
StringBuilder buf = new StringBuilder();
for (int i = 0; i < hex.length(); i += 2) {
@@ -139,12 +194,30 @@ public class PHPBB implements EncryptionMethod {
return buf.toString();
}
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
* @return String
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
*/
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return phpbb_hash(password, salt);
}
/**
* Method comparePassword.
* @param hash String
* @param password String
* @param playerName String
* @return boolean
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
@@ -11,8 +11,19 @@ import javax.crypto.spec.SecretKeySpec;
import fr.xephi.authme.AuthMe;
/**
*/
public class PHPFUSION implements EncryptionMethod {
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
* @return String
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
*/
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
@@ -40,6 +51,15 @@ public class PHPFUSION implements EncryptionMethod {
return digest;
}
/**
* Method comparePassword.
* @param hash String
* @param password String
* @param playerName String
* @return boolean
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
@@ -47,6 +67,12 @@ public class PHPFUSION implements EncryptionMethod {
return hash.equals(getHash(password, salt, ""));
}
/**
* Method getSHA1.
* @param message String
* @return String
* @throws NoSuchAlgorithmException
*/
private static String getSHA1(String message)
throws NoSuchAlgorithmException {
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
@@ -2,14 +2,34 @@ package fr.xephi.authme.security.crypts;
import java.security.NoSuchAlgorithmException;
/**
*/
public class PLAINTEXT implements EncryptionMethod {
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
* @return String
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
*/
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return password;
}
/**
* Method comparePassword.
* @param hash String
* @param password String
* @param playerName String
* @return boolean
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
@@ -3,8 +3,19 @@ package fr.xephi.authme.security.crypts;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
*/
public class ROYALAUTH implements EncryptionMethod {
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
* @return String
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
*/
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
@@ -13,6 +24,13 @@ public class ROYALAUTH implements EncryptionMethod {
return password;
}
/**
* Method hash.
* @param password String
* @param salt String
* @return String
* @throws NoSuchAlgorithmException
*/
public String hash(String password, String salt)
throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("SHA-512");
@@ -24,6 +42,15 @@ public class ROYALAUTH implements EncryptionMethod {
return sb.toString();
}
/**
* Method comparePassword.
* @param hash String
* @param password String
* @param playerName String
* @return boolean
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
@@ -6,14 +6,34 @@ import java.security.NoSuchAlgorithmException;
import fr.xephi.authme.AuthMe;
/**
*/
public class SALTED2MD5 implements EncryptionMethod {
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
* @return String
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
*/
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getMD5(getMD5(password) + salt);
}
/**
* Method comparePassword.
* @param hash String
* @param password String
* @param playerName String
* @return boolean
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
@@ -21,6 +41,12 @@ public class SALTED2MD5 implements EncryptionMethod {
return hash.equals(getMD5(getMD5(password) + salt));
}
/**
* Method getMD5.
* @param message String
* @return String
* @throws NoSuchAlgorithmException
*/
private static String getMD5(String message)
throws NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("MD5");
@@ -6,14 +6,34 @@ import java.security.NoSuchAlgorithmException;
import fr.xephi.authme.AuthMe;
/**
*/
public class SALTEDSHA512 implements EncryptionMethod {
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
* @return String
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
*/
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getSHA512(password + salt);
}
/**
* Method comparePassword.
* @param hash String
* @param password String
* @param playerName String
* @return boolean
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
@@ -21,6 +41,12 @@ public class SALTEDSHA512 implements EncryptionMethod {
return hash.equals(getHash(password, salt, ""));
}
/**
* Method getSHA512.
* @param message String
* @return String
* @throws NoSuchAlgorithmException
*/
private static String getSHA512(String message)
throws NoSuchAlgorithmException {
MessageDigest sha512 = MessageDigest.getInstance("SHA-512");
@@ -4,20 +4,46 @@ import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
*/
public class SHA1 implements EncryptionMethod {
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
* @return String
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
*/
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getSHA1(password);
}
/**
* Method comparePassword.
* @param hash String
* @param password String
* @param playerName String
* @return boolean
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return hash.equals(getHash(password, "", ""));
}
/**
* Method getSHA1.
* @param message String
* @return String
* @throws NoSuchAlgorithmException
*/
private static String getSHA1(String message)
throws NoSuchAlgorithmException {
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
@@ -4,14 +4,34 @@ import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
*/
public class SHA256 implements EncryptionMethod {
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
* @return String
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
*/
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return "$SHA$" + salt + "$" + getSHA256(getSHA256(password) + salt);
}
/**
* Method comparePassword.
* @param hash String
* @param password String
* @param playerName String
* @return boolean
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
@@ -19,6 +39,12 @@ public class SHA256 implements EncryptionMethod {
return hash.equals(getHash(password, line[2], ""));
}
/**
* Method getSHA256.
* @param message String
* @return String
* @throws NoSuchAlgorithmException
*/
private static String getSHA256(String message)
throws NoSuchAlgorithmException {
MessageDigest sha256 = MessageDigest.getInstance("SHA-256");
@@ -4,20 +4,46 @@ import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
*/
public class SHA512 implements EncryptionMethod {
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
* @return String
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
*/
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getSHA512(password);
}
/**
* Method comparePassword.
* @param hash String
* @param password String
* @param playerName String
* @return boolean
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return hash.equals(getHash(password, "", ""));
}
/**
* Method getSHA512.
* @param message String
* @return String
* @throws NoSuchAlgorithmException
*/
private static String getSHA512(String message)
throws NoSuchAlgorithmException {
MessageDigest sha512 = MessageDigest.getInstance("SHA-512");
@@ -4,20 +4,46 @@ import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
*/
public class SMF implements EncryptionMethod {
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
* @return String
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
*/
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getSHA1(name.toLowerCase() + password);
}
/**
* Method comparePassword.
* @param hash String
* @param password String
* @param playerName String
* @return boolean
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return hash.equals(getHash(password, null, playerName));
}
/**
* Method getSHA1.
* @param message String
* @return String
* @throws NoSuchAlgorithmException
*/
private static String getSHA1(String message)
throws NoSuchAlgorithmException {
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
@@ -6,14 +6,34 @@ import java.security.NoSuchAlgorithmException;
import fr.xephi.authme.AuthMe;
/**
*/
public class WBB3 implements EncryptionMethod {
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
* @return String
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
*/
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getSHA1(salt.concat(getSHA1(salt.concat(getSHA1(password)))));
}
/**
* Method comparePassword.
* @param hash String
* @param password String
* @param playerName String
* @return boolean
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
@@ -21,6 +41,12 @@ public class WBB3 implements EncryptionMethod {
return hash.equals(getHash(password, salt, ""));
}
/**
* Method getSHA1.
* @param message String
* @return String
* @throws NoSuchAlgorithmException
*/
private static String getSHA1(String message)
throws NoSuchAlgorithmException {
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
@@ -2,14 +2,34 @@ package fr.xephi.authme.security.crypts;
import java.security.NoSuchAlgorithmException;
/**
*/
public class WBB4 implements EncryptionMethod {
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
* @return String
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
*/
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return BCRYPT.getDoubleHash(password, salt);
}
/**
* Method comparePassword.
* @param hash String
* @param password String
* @param playerName String
* @return boolean
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
@@ -64,6 +64,8 @@ package fr.xephi.authme.security.crypts;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
/**
*/
public class WHIRLPOOL implements EncryptionMethod {
/**
@@ -319,6 +321,7 @@ public class WHIRLPOOL implements EncryptionMethod {
* Get the hash value from the hashing state.
*
* This method uses the invariant: bufferBits < 512
* @param digest byte[]
*/
public void NESSIEfinalize(byte[] digest) {
// append a '1'-bit:
@@ -373,6 +376,11 @@ public class WHIRLPOOL implements EncryptionMethod {
}
}
/**
* Method display.
* @param array byte[]
* @return String
*/
protected static String display(byte[] array) {
char[] val = new char[2 * array.length];
String hex = "0123456789ABCDEF";
@@ -384,6 +392,15 @@ public class WHIRLPOOL implements EncryptionMethod {
return String.valueOf(val);
}
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
* @return String
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
*/
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
@@ -394,6 +411,15 @@ public class WHIRLPOOL implements EncryptionMethod {
return display(digest);
}
/**
* Method comparePassword.
* @param hash String
* @param password String
* @param playerName String
* @return boolean
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
@@ -6,11 +6,19 @@ import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Arrays;
/**
*/
public class WORDPRESS implements EncryptionMethod {
private static final String itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
private SecureRandom randomGen = new SecureRandom();
/**
* Method encode64.
* @param src byte[]
* @param count int
* @return String
*/
private String encode64(byte[] src, int count) {
int i, value;
StringBuilder output = new StringBuilder();
@@ -45,6 +53,12 @@ public class WORDPRESS implements EncryptionMethod {
return output.toString();
}
/**
* Method crypt.
* @param password String
* @param setting String
* @return String
*/
private String crypt(String password, String setting) {
String output = "*0";
if (((setting.length() < 2) ? setting : setting.substring(0, 2)).equalsIgnoreCase(output)) {
@@ -83,6 +97,11 @@ public class WORDPRESS implements EncryptionMethod {
return output;
}
/**
* Method gensaltPrivate.
* @param input byte[]
* @return String
*/
private String gensaltPrivate(byte[] input) {
String output = "$P$";
int iterationCountLog2 = 8;
@@ -91,6 +110,11 @@ public class WORDPRESS implements EncryptionMethod {
return output;
}
/**
* Method stringToUtf8.
* @param string String
* @return byte[]
*/
private byte[] stringToUtf8(String string) {
try {
return string.getBytes("UTF-8");
@@ -99,6 +123,15 @@ public class WORDPRESS implements EncryptionMethod {
}
}
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
* @return String
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
*/
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
@@ -107,6 +140,15 @@ public class WORDPRESS implements EncryptionMethod {
return crypt(password, gensaltPrivate(stringToUtf8(new String(random))));
}
/**
* Method comparePassword.
* @param hash String
* @param password String
* @param playerName String
* @return boolean
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
@@ -2,8 +2,19 @@ package fr.xephi.authme.security.crypts;
import java.security.NoSuchAlgorithmException;
/**
*/
public class XAUTH implements EncryptionMethod {
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
* @return String
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
*/
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
@@ -12,6 +23,15 @@ public class XAUTH implements EncryptionMethod {
return hash.substring(0, saltPos) + salt + hash.substring(saltPos);
}
/**
* Method comparePassword.
* @param hash String
* @param password String
* @param playerName String
* @return boolean
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
@@ -20,6 +40,11 @@ public class XAUTH implements EncryptionMethod {
return hash.equals(getHash(password, salt, ""));
}
/**
* Method getWhirlpool.
* @param message String
* @return String
*/
public static String getWhirlpool(String message) {
WHIRLPOOL w = new WHIRLPOOL();
byte[] digest = new byte[WHIRLPOOL.DIGESTBYTES];
@@ -9,14 +9,34 @@ import java.util.regex.Pattern;
import fr.xephi.authme.AuthMe;
/**
*/
public class XF implements EncryptionMethod {
/**
* Method getHash.
* @param password String
* @param salt String
* @param name String
* @return String
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#getHash(String, String, String)
*/
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getSHA256(getSHA256(password) + regmatch("\"salt\";.:..:\"(.*)\";.:.:\"hashFunc\"", salt));
}
/**
* Method comparePassword.
* @param hash String
* @param password String
* @param playerName String
* @return boolean
* @throws NoSuchAlgorithmException
* @see fr.xephi.authme.security.crypts.EncryptionMethod#comparePassword(String, String, String)
*/
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
@@ -24,6 +44,12 @@ public class XF implements EncryptionMethod {
return hash.equals(regmatch("\"hash\";.:..:\"(.*)\";.:.:\"salt\"", salt));
}
/**
* Method getSHA256.
* @param password String
* @return String
* @throws NoSuchAlgorithmException
*/
public String getSHA256(String password) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(password.getBytes());
@@ -43,6 +69,12 @@ public class XF implements EncryptionMethod {
return hexString.toString();
}
/**
* Method regmatch.
* @param pattern String
* @param line String
* @return String
*/
public String regmatch(String pattern, String line) {
List<String> allMatches = new ArrayList<>();
Matcher m = Pattern.compile(pattern).matcher(line);