我有一个来自JAASRealm的函数login():
@Override
public boolean login() throws LoginException {
...
}
我只想在login()函数中使用这样的MessageDigest对象:
MessageDigest md = MessageDigest.getInstance("SHA-256");
但我接受了这个错误:
error: unreported exception NoSuchAlgorithmException; must be caught or declared to be thrown
所以我在login()之前创建了这个函数:
public String getPasswordDigest(String password) throws NoSuchAlgorithmException{
try{
MessageDigest md = MessageDigest.getInstance("SHA-256");
byte [] digestBytes = md.digest(password.getBytes(StandardCharsets.UTF_8));
String digestString = new String(digestBytes, StandardCharsets.UTF_8);
return digestString;
}catch(NoSuchAlgorithmException e){
throw new NoSuchAlgorithmException(e.getMessage());
}
}
}
然后,在login()函数中我调用:
String digestPassword = getPasswordDigest(saltedPassword);
但我得到同样的错误。
我尝试执行以下操作:
@Override
public boolean login() throws LoginException, NoSuchAlgorithmException {
但是我收到了这个错误:
login() in PlainLoginModule cannot implement login() in LoginModule
public boolean login() throws LoginException, NoSuchAlgorithmException {
^
overridden method does not throw NoSuchAlgorithmException
我不知道在这种情况下该怎么做......