Я новичок в вопросах безопасности с Java.У меня есть код, но я не смог его запустить, потому что есть ошибка
FirstCertificateSelector не может быть разрешен для типа,
DirectPasswordProvider не может быть разрешен для типа.
Код указан ниже:
public class Main {
private static final String CERT_FOLDER = "C:/Certs/";
private static final String CERT = "mycert.pfx";
private static final String PASS = "Password"; //the same in cert and keystorage
private static final String UNSIGNED = "C:/Test/sign-verify/unsigned.xml";
private static final String SIGNED = "C:/Test/sign-verify/signed-bes.xml";
private static final String DOCUMENT = "C:/Test/sign-verify/document.xml";
public static void main(String[] args) throws Exception {
System.out.println("______________________");
System.out.println("\tSign");
System.out.println("______________________");
signBes();
//System.out.println("______________________");
//System.out.println("\tVerify");
//System.out.println("______________________");
//verifyBes();
}
private static void signBes() throws Exception {
Document doc = DocumentBuilderFactory
.newInstance()
.newDocumentBuilder()
.parse(new File(DOCUMENT));
Element elem = doc.getDocumentElement();
DOMHelper.useIdAsXmlId(elem);
KeyingDataProvider kdp = new FileSystemKeyStoreKeyingDataProvider(
"pkcs12",
CERT_FOLDER + CERT,
new FirstCertificateSelector(),
new DirectPasswordProvider(PASS),
new DirectPasswordProvider(PASS),
true);
DataObjectDesc obj = new DataObjectReference("#" + elem.getAttribute("Id"))
.withTransform(new EnvelopedSignatureTransform());
SignedDataObjects dataObjs = new SignedDataObjects().withSignedDataObject(obj);
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null, null);
XadesSigner signer = new XadesBesSigningProfile(kdp).newSigner();
signer.sign(dataObjs, elem);
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File(SIGNED));
transformer.transform(source, result);
}
}