我正在尝试将密钥库作为资源读取。下面的示例代码。我遇到的问题是 inputStream 仍然为空。
import java.io.InputStream;
import java.util.List;
import org.linguafranca.pwdb.kdbx.KdbxCreds;
import org.linguafranca.pwdb.kdbx.simple.SimpleDatabase;
import org.linguafranca.pwdb.kdbx.simple.SimpleEntry;
import org.linguafranca.pwdb.Credentials;
import org.apache.log4j.Logger;
public class Security {
private static final String PATH = null;
private static final String KEYSTORE_PASSWORD = "admin";
static List<SimpleEntry> entries = null;
final static Logger logger = Logger.getLogger(Security.class);
public Security(){
//TODO: initialize security and it's passwords
}
public static void init(){
try {
//InputStream inputStream = new FileInputStream(".keePass.kdbx");
InputStream inputStream = Security.class.getClassLoader().getResourceAsStream("keePass.kdbx");
// password credentials
Credentials credentials = new KdbxCreds(KEYSTORE_PASSWORD.getBytes());
SimpleDatabase database = SimpleDatabase.load(credentials, inputStream);
// Jaxb implementation seems a lot faster than the DOM implementation
// visit all groups and entries and list them to console
entries = database.getRootGroup().getEntries();
}catch(Exception exception){
logger.error(exception);
}
}
}
首先,我认为这只是路径问题,但是即使文件本身位于类旁边,我也无法加载它。
即使我使用绝对路径,结果也是一样的。
我犯了什么错误?