AOXAdESTriPhaseSigner implements AOSigner { @Override public byte[] sign(final byte[] data, final String algorithm, final PrivateKey key, final Certificate[] certChain, final Properties xParams) throws AOException { return triPhaseOperation( this.signFormat, CRYPTO_OPERATION_SIGN, data, algorithm, key, certChain, xParams ); } protected  AOXAdESTriPhaseSigner(final String format);  AOXAdESTriPhaseSigner(); @Override byte[] sign(final byte[] data,
			           final String algorithm,
			           final PrivateKey key,
			           final Certificate[] certChain,
			           final Properties xParams); @Override final byte[] getData(final byte[] sign); @Override byte[] cosign(final byte[] data,
			             final byte[] sign,
			             final String algorithm,
			             final PrivateKey key,
			             final Certificate[] certChain,
			             final Properties xParams); @Override byte[] cosign(final byte[] sign,
			             final String algorithm,
			             final PrivateKey key,
			             final Certificate[] certChain,
			             final Properties xParams); @Override byte[] countersign(final byte[] sign,
			final String algorithm,
			final CounterSignTarget targetType,
			final Object[] targets,
			final PrivateKey key,
			final Certificate[] certChain,
			final Properties xParams); @Override final AOTreeModel getSignersStructure(final byte[] sign,
			                                     final boolean asSimpleSignInfo); @Override boolean isSign(final byte[] sign); @Override boolean isValidDataFile(final byte[] data); @Override String getSignedName(final String originalName, final String inText); @Override AOSignInfo getSignInfo(final byte[] sign); static final String DSIGNNS; static final String SIGNATURE_TAG; static final String COUNTERSIGN_TARGET_LEAFS; static final String COUNTERSIGN_TARGET_TREE; }
@SuppressWarnings("static-method") @Test public void pruebaFirmaXAdESASiCS() throws Exception { final byte[] data = AOUtil.getDataFromInputStream(ClassLoader.getSystemResourceAsStream(DATA_FILENAME)); final KeyStore ks = KeyStore.getInstance("PKCS12"); ks.load(ClassLoader.getSystemResourceAsStream(CERT_PATH), CERT_PASS.toCharArray()); final PrivateKeyEntry pke = (PrivateKeyEntry) ks.getEntry(CERT_ALIAS, new KeyStore.PasswordProtection(CERT_PASS.toCharArray())); final AOSigner signer = new AOXAdESASiCSTriPhaseSigner(); for (final Properties config : CONFIGS) { final byte[] result = signer.sign(data, AOSignConstants.SIGN_ALGORITHM_SHA1WITHRSA, pke.getPrivateKey(), pke.getCertificateChain(), config); final File tempFile = File.createTempFile("xades-asic-s-", ".zip"); final FileOutputStream fos = new FileOutputStream(tempFile); fos.write(result); fos.close(); System.out.println("El resultado de la firma se ha guardado en: " + tempFile.getAbsolutePath()); } }
@SuppressWarnings("static-method") @Test public void pruebaFirmaXAdESDetached() throws Exception { final byte[] data = AOUtil.getDataFromInputStream( ClassLoader.getSystemResourceAsStream("TEST_PDF_Certified.pdf") ); final KeyStore ks = KeyStore.getInstance("PKCS12"); ks.load(ClassLoader.getSystemResourceAsStream(CERT_PATH), CERT_PASS.toCharArray()); final PrivateKeyEntry pke = (PrivateKeyEntry) ks.getEntry(CERT_ALIAS, new KeyStore.PasswordProtection(CERT_PASS.toCharArray())); final AOXAdESTriPhaseSigner signer = new AOXAdESTriPhaseSigner(); final Properties config = new Properties(); config.put("format", "XAdES Detached"); config.setProperty("serverUrl", SERVER_URL); final byte[] result = signer.sign( data, AOSignConstants.SIGN_ALGORITHM_SHA1WITHRSA, pke.getPrivateKey(), pke.getCertificateChain(), config ); final File tempFile = File.createTempFile("xades-", ".xml"); final FileOutputStream fos = new FileOutputStream(tempFile); fos.write(result); fos.close(); System.out.println("El resultado de la firma se ha guardado en: " + tempFile.getAbsolutePath()); }
@SuppressWarnings("static-method") @Test public void pruebaFirmaXAdESEnveloping() throws Exception { final byte[] data = AOUtil.getDataFromInputStream( ClassLoader.getSystemResourceAsStream("TEST_PDF_Certified.pdf") ); final KeyStore ks = KeyStore.getInstance("PKCS12"); ks.load(ClassLoader.getSystemResourceAsStream(CERT_PATH), CERT_PASS.toCharArray()); final PrivateKeyEntry pke = (PrivateKeyEntry) ks.getEntry(CERT_ALIAS, new KeyStore.PasswordProtection(CERT_PASS.toCharArray())); final AOXAdESTriPhaseSigner signer = new AOXAdESTriPhaseSigner(); final Properties config = new Properties(); config.put("format", "XAdES Enveloping"); config.setProperty("serverUrl", SERVER_URL); final byte[] result = signer.sign( data, AOSignConstants.SIGN_ALGORITHM_SHA1WITHRSA, pke.getPrivateKey(), pke.getCertificateChain(), config ); final File tempFile = File.createTempFile("xades-", ".xml"); final FileOutputStream fos = new FileOutputStream(tempFile); fos.write(result); fos.close(); System.out.println("El resultado de la firma se ha guardado en: " + tempFile.getAbsolutePath()); }
@SuppressWarnings("static-method") @Test public void pruebaFirmaXAdESEnveloped() throws Exception { final byte[] data = AOUtil.getDataFromInputStream( ClassLoader.getSystemResourceAsStream("xml_with_ids.xml") ); final KeyStore ks = KeyStore.getInstance("PKCS12"); ks.load(ClassLoader.getSystemResourceAsStream(CERT_PATH), CERT_PASS.toCharArray()); final PrivateKeyEntry pke = (PrivateKeyEntry) ks.getEntry(CERT_ALIAS, new KeyStore.PasswordProtection(CERT_PASS.toCharArray())); final AOXAdESTriPhaseSigner signer = new AOXAdESTriPhaseSigner(); final Properties config = new Properties(); config.put("format", "XAdES Enveloped"); config.setProperty("serverUrl", SERVER_URL); final byte[] result = signer.sign( data, AOSignConstants.SIGN_ALGORITHM_SHA1WITHRSA, pke.getPrivateKey(), pke.getCertificateChain(), config ); final File tempFile = File.createTempFile("xades-", ".xml"); final FileOutputStream fos = new FileOutputStream(tempFile); fos.write(result); fos.close(); System.out.println("El resultado de la firma XAdES Enveloped se ha guardado en: " + tempFile.getAbsolutePath()); }
@SuppressWarnings("static-method") @Test public void pruebaFirmaXAdES() throws Exception { final byte[] data = AOUtil.getDataFromInputStream(ClassLoader.getSystemResourceAsStream(DATA_FILENAME)); final KeyStore ks = KeyStore.getInstance("PKCS12"); ks.load(ClassLoader.getSystemResourceAsStream(CERT_PATH), CERT_PASS.toCharArray()); final PrivateKeyEntry pke = (PrivateKeyEntry) ks.getEntry(CERT_ALIAS, new KeyStore.PasswordProtection(CERT_PASS.toCharArray())); final AOXAdESTriPhaseSigner signer = new AOXAdESTriPhaseSigner(); for (final Properties config : CONFIGS) { final byte[] result = signer.sign(data, AOSignConstants.SIGN_ALGORITHM_SHA1WITHRSA, pke.getPrivateKey(), pke.getCertificateChain(), config); final File tempFile = File.createTempFile("xades-", ".xml"); final FileOutputStream fos = new FileOutputStream(tempFile); fos.write(result); fos.close(); System.out.println("El resultado de la firma se ha guardado en: " + tempFile.getAbsolutePath()); } }