我收到错误消息“不兼容的类型。必需:字节[]。找到:java.lang.string
我已经尝试从发现的不兼容类型和要求相同的类型中解决方案,这表明我必须初始化类型。我初始化了byte [],但仍然收到该错误
public static byte[] hash(char[] password, byte[] salt) {
PBEKeySpec spec = new PBEKeySpec(password, salt, ITERATIONS, KEY_LENGTH);
Arrays.fill(password, Character.MIN_VALUE);
try {
SecretKeyFactory skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
byte [] hashedPass = skf.generateSecret(spec).getEncoded();
return toHex(hashedPass);
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
throw new AssertionError("Error while hashing a password: " + e.getMessage(), e);
} finally {
spec.clearPassword();
}
}
public static String toHex(byte[] Array){
BigInteger bi = new BigInteger(1, Array);
String hex = bi.toString(16);
int paddingLength = (Array.length *2) - hex.length();
if (paddingLength > 0){
return String.format("%0" + paddingLength +"d", 0) + hex;
} else {
return hex;
}
}
我在第7行出现错误:
return toHex(hashedPass);
米脂
相关分类