當前位置: 首頁>>代碼示例>>Java>>正文


Java Transform類代碼示例

本文整理匯總了Java中javax.xml.crypto.dsig.Transform的典型用法代碼示例。如果您正苦於以下問題:Java Transform類的具體用法?Java Transform怎麽用?Java Transform使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Transform類屬於javax.xml.crypto.dsig包,在下文中一共展示了Transform類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: marshal

import javax.xml.crypto.dsig.Transform; //導入依賴的package包/類
@Override
public void marshal(XmlWriter xwriter, String dsPrefix, XMLCryptoContext context)
    throws MarshalException
{
    xwriter.writeStartElement(dsPrefix, "RetrievalMethod", XMLSignature.XMLNS);

    // TODO - see whether it is important to capture the "here" attribute as part of the
    // marshalling - do any of the tests fail?
    // add URI and Type attributes
    here = xwriter.writeAttribute("", "", "URI", uri);
    xwriter.writeAttribute("", "", "Type", type);

    // add Transforms elements
    if (!transforms.isEmpty()) {
        xwriter.writeStartElement(dsPrefix, "Transforms", XMLSignature.XMLNS);
        for (Transform transform : transforms) {
            ((DOMTransform)transform).marshal(xwriter, dsPrefix, context);
        }
        xwriter.writeEndElement(); // "Transforms"
    }
    xwriter.writeEndElement(); // "RetrievalMethod"
}
 
開發者ID:Legostaev,項目名稱:xmlsec-gost,代碼行數:23,代碼來源:DOMRetrievalMethod.java

示例2: get

import javax.xml.crypto.dsig.Transform; //導入依賴的package包/類
@Override
public Output get(Input input) throws Exception {

    Transform transform = input.getSignatureFactory().newTransform(CanonicalizationMethod.INCLUSIVE, (TransformParameterSpec) null);
    Reference ref = input.getSignatureFactory().newReference("#propertiesObject",
            input.getSignatureFactory().newDigestMethod(input.getContentDigestAlgorithm(), null), Collections.singletonList(transform),
            null, null);

    String doc2 = "<ts:timestamp xmlns:ts=\"http:/timestamp\">" + System.currentTimeMillis() + "</ts:timestamp>";
    InputStream is = new ByteArrayInputStream(doc2.getBytes("UTF-8"));
    Document doc = XmlSignatureHelper.newDocumentBuilder(Boolean.TRUE).parse(is);
    DOMStructure structure = new DOMStructure(doc.getDocumentElement());

    SignatureProperty prop = input.getSignatureFactory().newSignatureProperty(Collections.singletonList(structure),
            input.getSignatureId(), "property");
    SignatureProperties properties = input.getSignatureFactory().newSignatureProperties(Collections.singletonList(prop), "properties");
    XMLObject propertiesObject = input.getSignatureFactory().newXMLObject(Collections.singletonList(properties), "propertiesObject",
            null, null);

    XmlSignatureProperties.Output result = new Output();
    result.setReferences(Collections.singletonList(ref));
    result.setObjects(Collections.singletonList(propertiesObject));

    return result;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:26,代碼來源:TimestampProperty.java

示例3: sign

import javax.xml.crypto.dsig.Transform; //導入依賴的package包/類
public <T extends Node> T sign(T node) {
	checkNotNull(node);
	checkArgument(node instanceof Document || node instanceof Element);
	try {
		Element element = node instanceof Document ? ((Document) node).getDocumentElement() : (Element) node;
		DOMSignContext dsc = new DOMSignContext(privateKey, element);
		XMLSignatureFactory signatureFactory = XMLSignatureFactory.getInstance("DOM");

		List<Transform> transformList = new LinkedList<>();
		transformList.add(signatureFactory.newTransform(Transform.ENVELOPED, (TransformParameterSpec) null));
		transformList.add(signatureFactory.newTransform(C14N_TRANSFORM_METHOD, (TransformParameterSpec) null));

		Node child = findFirstElementChild(element);
		((Element) child).setIdAttribute("Id", true);

		String id = child.getAttributes().getNamedItem("Id").getNodeValue();
		String uri = String.format("#%s", id);
		Reference reference = signatureFactory.newReference(uri,
				signatureFactory.newDigestMethod(DigestMethod.SHA1, null), transformList, null, null);

		SignedInfo signedInfo = signatureFactory.newSignedInfo(signatureFactory.newCanonicalizationMethod(
				CanonicalizationMethod.INCLUSIVE, (C14NMethodParameterSpec) null), signatureFactory
				.newSignatureMethod(SignatureMethod.RSA_SHA1, null), Collections.singletonList(reference));

		KeyInfoFactory kif = signatureFactory.getKeyInfoFactory();
		X509Data x509Data = kif.newX509Data(Collections.singletonList(certificateChain[0]));
		KeyInfo keyInfo = kif.newKeyInfo(Collections.singletonList(x509Data));

		XMLSignature xmlSignature = signatureFactory.newXMLSignature(signedInfo, keyInfo);

		xmlSignature.sign(dsc);

		return node;
	}
	catch (Exception ex) {
		throw new IllegalArgumentException("Erro ao assinar XML.", ex);
	}
}
 
開發者ID:yanaga,項目名稱:opes,代碼行數:39,代碼來源:CertificadoDigital.java

示例4: XmlSignatureHandler

import javax.xml.crypto.dsig.Transform; //導入依賴的package包/類
public XmlSignatureHandler() throws NoSuchAlgorithmException,
		InvalidAlgorithmParameterException {
	this.builderFactory = DocumentBuilderFactory.newInstance();
	this.builderFactory.setNamespaceAware(true);
	this.transformerFactory = TransformerFactory.newInstance();
	this.signatureFactory = XMLSignatureFactory.getInstance("DOM");
	this.digestMethod = signatureFactory.newDigestMethod(DigestMethod.SHA1, null);
	this.transformList = new ArrayList<Transform>(2);

	this.transformList.add(
			signatureFactory.newTransform(
					Transform.ENVELOPED,
					(TransformParameterSpec) null));

	this.transformList.add(
			signatureFactory.newTransform(
					"http://www.w3.org/TR/2001/REC-xml-c14n-20010315",
					(TransformParameterSpec) null));

	this.canonicalizationMethod = this.signatureFactory.newCanonicalizationMethod(
			CanonicalizationMethod.INCLUSIVE,
			(C14NMethodParameterSpec) null);

	this.signatureMethod = this.signatureFactory.newSignatureMethod(SignatureMethod.RSA_SHA1, null);
	this.keyInfoFactory = this.signatureFactory.getKeyInfoFactory();

}
 
開發者ID:EixoX,項目名稱:jetfuel,代碼行數:28,代碼來源:XmlSignatureHandler.java

示例5: signSamlElement

import javax.xml.crypto.dsig.Transform; //導入依賴的package包/類
/**
 * Sign SAML element.
 *
 * @param element the element
 * @param privKey the priv key
 * @param pubKey  the pub key
 * @return the element
 */
private static org.jdom.Element signSamlElement(final org.jdom.Element element, final PrivateKey privKey, final PublicKey pubKey) {
    try {
        final String providerName = System.getProperty("jsr105Provider", SIGNATURE_FACTORY_PROVIDER_CLASS);

        final XMLSignatureFactory sigFactory = XMLSignatureFactory
                .getInstance("DOM", (Provider) Class.forName(providerName).newInstance());

        final List<Transform> envelopedTransform = Collections.singletonList(sigFactory.newTransform(Transform.ENVELOPED,
                (TransformParameterSpec) null));

        final Reference ref = sigFactory.newReference(StringUtils.EMPTY, sigFactory
                .newDigestMethod(DigestMethod.SHA1, null), envelopedTransform, null, null);

        // Create the SignatureMethod based on the type of key
        final SignatureMethod signatureMethod;
        final String algorithm = pubKey.getAlgorithm();
        switch (algorithm) {
            case "DSA":
                signatureMethod = sigFactory.newSignatureMethod(SignatureMethod.DSA_SHA1, null);
                break;
            case "RSA":
                signatureMethod = sigFactory.newSignatureMethod(SignatureMethod.RSA_SHA1, null);
                break;
            default:
                throw new RuntimeException("Error signing SAML element: Unsupported type of key");
        }

        final CanonicalizationMethod canonicalizationMethod = sigFactory
                .newCanonicalizationMethod(
                        CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS,
                        (C14NMethodParameterSpec) null);

        // Create the SignedInfo
        final SignedInfo signedInfo = sigFactory.newSignedInfo(
                canonicalizationMethod, signatureMethod, Collections.singletonList(ref));

        // Create a KeyValue containing the DSA or RSA PublicKey
        final KeyInfoFactory keyInfoFactory = sigFactory.getKeyInfoFactory();
        final KeyValue keyValuePair = keyInfoFactory.newKeyValue(pubKey);

        // Create a KeyInfo and add the KeyValue to it
        final KeyInfo keyInfo = keyInfoFactory.newKeyInfo(Collections.singletonList(keyValuePair));
        // Convert the JDOM document to w3c (Java XML signature API requires w3c representation)
        final Element w3cElement = toDom(element);

        // Create a DOMSignContext and specify the DSA/RSA PrivateKey and
        // location of the resulting XMLSignature's parent element
        final DOMSignContext dsc = new DOMSignContext(privKey, w3cElement);

        final Node xmlSigInsertionPoint = getXmlSignatureInsertLocation(w3cElement);
        dsc.setNextSibling(xmlSigInsertionPoint);

        // Marshal, generate (and sign) the enveloped signature
        final XMLSignature signature = sigFactory.newXMLSignature(signedInfo, keyInfo);
        signature.sign(dsc);

        return toJdom(w3cElement);

    } catch (final Exception e) {
        throw new RuntimeException("Error signing SAML element: " + e.getMessage(), e);
    }
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:71,代碼來源:AbstractSamlObjectBuilder.java

示例6: RequestSigner

import javax.xml.crypto.dsig.Transform; //導入依賴的package包/類
public RequestSigner ( final Configuration configuration ) throws Exception
{
    this.fac = XMLSignatureFactory.getInstance ( "DOM" );
    this.md = this.fac.newDigestMethod ( configuration.getDigestMethod (), null );
    this.kif = this.fac.getKeyInfoFactory ();

    this.t = this.fac.newTransform ( Transform.ENVELOPED, (TransformParameterSpec)null );
    this.ref = this.fac.newReference ( "", this.md, Collections.singletonList ( this.t ), null, null );
    this.cm = this.fac.newCanonicalizationMethod ( CanonicalizationMethod.INCLUSIVE, (C14NMethodParameterSpec)null );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:11,代碼來源:RequestSigner.java

示例7: sign

import javax.xml.crypto.dsig.Transform; //導入依賴的package包/類
public Document sign(FileInputStream fileStream, KeyPair keyPair)
        throws ParserConfigurationException, SAXException, IOException,
        NoSuchAlgorithmException, InvalidAlgorithmParameterException,
        KeyException, MarshalException, XMLSignatureException {

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);

    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse(fileStream);

    DOMSignContext signContext = new DOMSignContext(keyPair.getPrivate(),
            document.getDocumentElement());
    XMLSignatureFactory signFactory = XMLSignatureFactory
            .getInstance("DOM");
    Reference ref = signFactory.newReference("", signFactory
            .newDigestMethod(digestMethod, null), Collections
            .singletonList(signFactory.newTransform(Transform.ENVELOPED,
                    (TransformParameterSpec) null)), null, null);
    SignedInfo si = signFactory.newSignedInfo(signFactory
            .newCanonicalizationMethod(
                    CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS,
                    (C14NMethodParameterSpec) null), signFactory
            .newSignatureMethod(signatureMethod, null), Collections
            .singletonList(ref));

    KeyInfoFactory kif = signFactory.getKeyInfoFactory();
    KeyValue kv = kif.newKeyValue(keyPair.getPublic());
    KeyInfo ki = kif.newKeyInfo(Collections.singletonList(kv));

    XMLSignature signature = signFactory.newXMLSignature(si, ki);
    signature.sign(signContext);

    return document;
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:36,代碼來源:XMLSignatureBuilder.java

示例8: newRetrievalMethod

import javax.xml.crypto.dsig.Transform; //導入依賴的package包/類
public RetrievalMethod newRetrievalMethod(String uri, String type,
    List<? extends Transform> transforms) {
    if (uri == null) {
        throw new NullPointerException("uri must not be null");
    }
    return new DOMRetrievalMethod(uri, type, transforms);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:DOMKeyInfoFactory.java

示例9: main

import javax.xml.crypto.dsig.Transform; //導入依賴的package包/類
public static void main(String[] args) throws NoSuchAlgorithmException {
   try {
       TransformService ts = TransformService.getInstance(
           Transform.BASE64, "DOM", "SomeProviderThatDoesNotExist");
   }
   catch(NoSuchProviderException e) {
       // this is expected
   }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:10,代碼來源:UnknownProvider.java

示例10: DOMRetrievalMethod

import javax.xml.crypto.dsig.Transform; //導入依賴的package包/類
/**
 * Creates a <code>DOMRetrievalMethod</code> containing the specified
 * URIReference and List of Transforms.
 *
 * @param uri the URI
 * @param type the type
 * @param transforms a list of {@link Transform}s. The list is defensively
 *    copied to prevent subsequent modification. May be <code>null</code>
 *    or empty.
 * @throws IllegalArgumentException if the format of <code>uri</code> is
 *    invalid, as specified by Reference's URI attribute in the W3C
 *    specification for XML-Signature Syntax and Processing
 * @throws NullPointerException if <code>uriReference</code>
 *    is <code>null</code>
 * @throws ClassCastException if <code>transforms</code> contains any
 *    entries that are not of type {@link Transform}
 */
public DOMRetrievalMethod(String uri, String type,
                          List<? extends Transform> transforms)
{
    if (uri == null) {
        throw new NullPointerException("uri cannot be null");
    }
    if (transforms == null || transforms.isEmpty()) {
        this.transforms = Collections.emptyList();
    } else {
        this.transforms = Collections.unmodifiableList(
            new ArrayList<Transform>(transforms));
        for (int i = 0, size = this.transforms.size(); i < size; i++) {
            if (!(this.transforms.get(i) instanceof Transform)) {
                throw new ClassCastException
                    ("transforms["+i+"] is not a valid type");
            }
        }
    }
    this.uri = uri;
    if (!uri.equals("")) {
        try {
            new URI(uri);
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException(e.getMessage());
        }
    }

    this.type = type;
}
 
開發者ID:Legostaev,項目名稱:xmlsec-gost,代碼行數:47,代碼來源:DOMRetrievalMethod.java

示例11: equals

import javax.xml.crypto.dsig.Transform; //導入依賴的package包/類
@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }

    if (!(o instanceof Transform)) {
        return false;
    }
    Transform otransform = (Transform)o;

    return getAlgorithm().equals(otransform.getAlgorithm()) &&
            DOMUtils.paramsEqual(getParameterSpec(),
                                 otransform.getParameterSpec());
}
 
開發者ID:Legostaev,項目名稱:xmlsec-gost,代碼行數:16,代碼來源:DOMTransform.java

示例12: assinarDocumento

import javax.xml.crypto.dsig.Transform; //導入依賴的package包/類
public String assinarDocumento(final String conteudoXml) throws Exception {
    final KeyStore keyStore = KeyStore.getInstance("PKCS12");
    try (InputStream certificadoStream = new ByteArrayInputStream(this.config.getCertificado())) {
        keyStore.load(certificadoStream, this.config.getCertificadoSenha().toCharArray());
    }

    final KeyStore.PrivateKeyEntry keyEntry = (KeyStore.PrivateKeyEntry) keyStore.getEntry(keyStore.aliases().nextElement(), new KeyStore.PasswordProtection(this.config.getCertificadoSenha().toCharArray()));
    final XMLSignatureFactory signatureFactory = XMLSignatureFactory.getInstance("DOM");

    final List<Transform> transforms = new ArrayList<>(2);
    transforms.add(signatureFactory.newTransform(Transform.ENVELOPED, (TransformParameterSpec) null));
    transforms.add(signatureFactory.newTransform(AssinaturaDigital.C14N_TRANSFORM_METHOD, (TransformParameterSpec) null));

    final KeyInfoFactory keyInfoFactory = signatureFactory.getKeyInfoFactory();
    final X509Data x509Data = keyInfoFactory.newX509Data(Collections.singletonList((X509Certificate) keyEntry.getCertificate()));
    final KeyInfo keyInfo = keyInfoFactory.newKeyInfo(Collections.singletonList(x509Data));

    final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    documentBuilderFactory.setNamespaceAware(true);

    try (StringReader stringReader = new StringReader(conteudoXml)) {
        final Document document = documentBuilderFactory.newDocumentBuilder().parse(new InputSource(stringReader));
        for (final String elementoAssinavel : AssinaturaDigital.ELEMENTOS_ASSINAVEIS) {
            final NodeList elements = document.getElementsByTagName(elementoAssinavel);
            for (int i = 0; i < elements.getLength(); i++) {
                final Element element = (Element) elements.item(i);
                final String id = element.getAttribute("Id");
                element.setIdAttribute("Id", true);

                final Reference reference = signatureFactory.newReference("#" + id, signatureFactory.newDigestMethod(DigestMethod.SHA1, null), transforms, null, null);
                final SignedInfo signedInfo = signatureFactory.newSignedInfo(signatureFactory.newCanonicalizationMethod(CanonicalizationMethod.INCLUSIVE, (C14NMethodParameterSpec) null), signatureFactory.newSignatureMethod(SignatureMethod.RSA_SHA1, null), Collections.singletonList(reference));

                final XMLSignature signature = signatureFactory.newXMLSignature(signedInfo, keyInfo);
                signature.sign(new DOMSignContext(keyEntry.getPrivateKey(), element.getParentNode()));
            }
        }
        return this.converteDocumentParaXml(document);
    }
}
 
開發者ID:GilbertoMattos,項目名稱:nfce,代碼行數:40,代碼來源:AssinaturaDigital.java

示例13: getXslTranform

import javax.xml.crypto.dsig.Transform; //導入依賴的package包/類
/**
 * Returns a configuration for an XSL transformation.
 * 
 * @param is
 *            input stream of the XSL
 * @return XSL transform
 * @throws IllegalArgumentException
 *             if <tt>is</tt> is <code>null</code>
 * @throws Exception
 *             if an error during the reading of the XSL file occurs
 */
public static AlgorithmMethod getXslTranform(InputStream is) throws SAXException, IOException, ParserConfigurationException {
    if (is == null) {
        throw new IllegalArgumentException("is must not be null");
    }
    Document doc = parseInput(is);
    DOMStructure stylesheet = new DOMStructure(doc.getDocumentElement());
    XSLTTransformParameterSpec spec = new XSLTTransformParameterSpec(stylesheet);
    XmlSignatureTransform transformXslt = new XmlSignatureTransform();
    transformXslt.setAlgorithm(Transform.XSLT);
    transformXslt.setParameterSpec(spec);
    return transformXslt;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:24,代碼來源:XmlSignatureHelper.java

示例14: createReference

import javax.xml.crypto.dsig.Transform; //導入依賴的package包/類
protected Reference createReference(XMLSignatureFactory fac, String uri, String type, SignatureType sigType, String id, Message message)
    throws InvalidAlgorithmParameterException, XmlSignatureException {
    try {
        List<Transform> transforms = getTransforms(fac, sigType, message);
        Reference ref = fac.newReference(uri, fac.newDigestMethod(getDigestAlgorithmUri(), null), transforms, type, id);
        return ref;
    } catch (NoSuchAlgorithmException e) {
        throw new XmlSignatureException("Wrong algorithm specified in the configuration.", e);
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:11,代碼來源:XmlSignerProcessor.java

示例15: containsEnvelopedTransform

import javax.xml.crypto.dsig.Transform; //導入依賴的package包/類
private boolean containsEnvelopedTransform(List<AlgorithmMethod> configuredTrafos) {
    for (AlgorithmMethod m : configuredTrafos) {
        if (Transform.ENVELOPED.equals(m.getAlgorithm())) {
            return true;
        }
    }
    return false;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:9,代碼來源:XmlSignerProcessor.java


注:本文中的javax.xml.crypto.dsig.Transform類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。