Skip to content

Instantly share code, notes, and snippets.

@hkneptune
hkneptune / xml_signing.java
Created October 9, 2023 03:51
Signing XML File Content with p12 File
public static String signXmlContent(String inputFile, String keyStoreFilePath,
String keyStorePassword, String keyStoreAlias) throws Exception {
KeyStore keyStore = KeyStore.getInstance("PKCS12");
keyStore.load(new FileInputStream(keyStoreFilePath), keyStorePassword.toCharArray());
DocumentBuilderFactory buildFactory = DocumentBuilderFactory.newInstance();
buildFactory.setNamespaceAware(true);
Document document = buildFactory.newDocumentBuilder().parse(inputFile);
XMLSignatureFactory xmLSignatureFactory = XMLSignatureFactory.getInstance("DOM",
(Provider) Class.forName("org.jcp.xml.dsig.internal.dom.XMLDSigRI").newInstance());
@hkneptune
hkneptune / sha256sum.java
Created October 9, 2023 03:58
SHA256Sum
public static String sha256(File input) throws IOException {
Digest sha256 = new Digest();
sha256.update(Files.readAllBytes(input.toPath()));
StringBuilder buff = new StringBuilder();
for (byte b : sha256.digest()) {
buff.append(String.format("%02x", b & 0xFF));
}