我正在使用一种登录方法来检查phpbb安装中的密码和用户名。
我需要做这项工作来解密phpbb加密。
我收到此错误:
vBulletin.java:139: error: non-static method phpbb_hash(String) cannot be referenced from a static context
pass2 = PHPBB3Password.phpbb_hash(password);
^
1 error
这是我的代码:
returnCodes[1] = group;
String pass2 = "";
if (forum == Type.myBB) {
pass2 = MD5.MD5(MD5.MD5(salt) + MD5.MD5(password));
} else if (forum == Type.vBulletin) {
pass2 = MD5.MD5(password);
pass2 = MD5.MD5(pass2 + salt);
} else if (forum == Type.SMF) {
pass2 = MD5.SHA((name.toLowerCase()) + password);
} else if (forum == Type.phpBB) {
pass2 = PHPBB3Password.phpbb_hash(password);
} else if (forum == Type.IPB) {
pass2 = MD5.MD5(MD5.MD5(salt) + MD5.MD5(password));
}
这是我正在使用的PhpBB:
public String phpbb_hash(String password) {
String random_state = unique_id();
String random = "";
int count = 6;
if (random.length() < count) {
random = "";
for (int i = 0; i < count; i += 16) {
random_state = md5(unique_id() + random_state);
random += pack(md5(random_state));
}
random = random.substring(0, count);
}
String hash = _hash_crypt_private(password, _hash_gensalt_private(random, itoa64));
if (hash.length() == 34)
return hash;
return md5(password);
}
旧的md5解密器虽然有效但不是最新的:
public static String MD5(String text)
throws NoSuchAlgorithmException, UnsupportedEncodingException {
MessageDigest md;
md = MessageDigest.getInstance("MD5");
byte[] md5hash = new byte[32];
md.update(text.getBytes("iso-8859-1"), 0, text.length());
md5hash = md.digest();
return convertToHex(md5hash);
}
更新:遵循某些评论者所说的话:D
PHPBB3Password.java:18: error: non-static method unique_id() cannot be referenced from a static context
String random_state = unique_id();
^
PHPBB3Password.java:26: error: non-static method unique_id() cannot be referenced from a static context
random_state = md5(unique_id() + random_state);
^
PHPBB3Password.java:32: error: non-static variable itoa64 cannot be referenced from a static context
String hash = _hash_crypt_private(password, _hash_gensalt_private(random, itoa64));
^
PHPBB3Password.java:32: error: non-static method _hash_gensalt_private(String,String) cannot be referenced from a static context
String hash = _hash_crypt_private(password, _hash_gensalt_private(random, itoa64));
^
PHPBB3Password.java:32: error: non-static method _hash_crypt_private(String,String) cannot be referenced from a static context
String hash = _hash_crypt_private(password, _hash_gensalt_private(random, itoa64));
^
5 errors
答案 0 :(得分:0)
如果phpbb_hash使用某些类属性,那么您需要一个PHPBB3Password实例来访问它。所以你会做类似的事情:
pass2 = new PHPBB3Password().phpbb_hash(password);
如果phpbb_hash不使用某些类属性,则应将此方法声明为静态,如下所示:
public static String phpbb_hash(String password) {
...
}