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


Java C14NMethodParameterSpec類代碼示例

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


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

示例1: sign

import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec; //導入依賴的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

示例2: XmlSignatureHandler

import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec; //導入依賴的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

示例3: signSamlElement

import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec; //導入依賴的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

示例4: RequestSigner

import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec; //導入依賴的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

示例5: sign

import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec; //導入依賴的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

示例6: init

import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec; //導入依賴的package包/類
public void init(TransformParameterSpec params)
    throws InvalidAlgorithmParameterException
{
    if (params != null) {
        if (!(params instanceof ExcC14NParameterSpec)) {
            throw new InvalidAlgorithmParameterException
                ("params must be of type ExcC14NParameterSpec");
        }
        this.params = (C14NMethodParameterSpec)params;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:12,代碼來源:DOMExcC14NMethod.java

示例7: setup

import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec; //導入依賴的package包/類
private void setup() throws Exception {
    ss = new ServerSocket(0);
    Thread thr = new Thread(this);
    thr.start();

    fac = XMLSignatureFactory.getInstance();
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    db = dbf.newDocumentBuilder();
    sha1 = fac.newDigestMethod(DigestMethod.SHA1, null);
    withoutComments = fac.newCanonicalizationMethod
        (CanonicalizationMethod.INCLUSIVE, (C14NMethodParameterSpec)null);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:14,代碼來源:XMLDSigWithSecMgr.java

示例8: init

import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec; //導入依賴的package包/類
@Override
public void init(TransformParameterSpec params)
    throws InvalidAlgorithmParameterException
{
    if (params != null) {
        if (!(params instanceof ExcC14NParameterSpec)) {
            throw new InvalidAlgorithmParameterException
                ("params must be of type ExcC14NParameterSpec");
        }
        this.params = (C14NMethodParameterSpec)params;
    }
}
 
開發者ID:Legostaev,項目名稱:xmlsec-gost,代碼行數:13,代碼來源:DOMExcC14NMethod.java

示例9: testCreateSignatureWithEmptyId

import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec; //導入依賴的package包/類
@org.junit.Test
public void testCreateSignatureWithEmptyId() throws Exception {
    // create references
    DigestMethod dm = fac.newDigestMethod(DigestMethod.SHA1, null);
    List<Reference> refs = Collections.singletonList
        (fac.newReference("#", dm));

    // create SignedInfo
    CanonicalizationMethod cm = fac.newCanonicalizationMethod
        (CanonicalizationMethod.INCLUSIVE, (C14NMethodParameterSpec) null);
    SignedInfo si = fac.newSignedInfo(cm, SIG_METHODS[1], refs);

    // create object with empty id
    Document doc = TestUtils.newDocument();
    XMLObject obj = fac.newXMLObject(Collections.singletonList
        (new DOMStructure(doc.createTextNode("I am the text."))),
        "", "text/plain", null);

    KeyInfo	ki = kifac.newKeyInfo(Collections.singletonList
                (kifac.newKeyValue((PublicKey) VALIDATE_KEYS[1])));

    // create XMLSignature
    XMLSignature sig = fac.newXMLSignature(si, ki,
                                           Collections.singletonList(obj),
                                           "signature", null);
    DOMSignContext dsc = new DOMSignContext(SIGN_KEYS[1], doc);
    sig.sign(dsc);
}
 
開發者ID:Legostaev,項目名稱:xmlsec-gost,代碼行數:29,代碼來源:XMLSignatureTest.java

示例10: createSignedInfo

import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec; //導入依賴的package包/類
private SignedInfo createSignedInfo(SignatureMethod sm) throws Exception {
    // set up the building blocks
    CanonicalizationMethod cm = fac.newCanonicalizationMethod
        (CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS,
         (C14NMethodParameterSpec) null);
    DigestMethod dm = fac.newDigestMethod(DigestMethod.SHA1, null);
    List<Reference> refs = Collections.singletonList(fac.newReference
        ("http://www.w3.org/Signature/2002/04/xml-stylesheet.b64", dm));
    return fac.newSignedInfo(cm, sm, refs);
}
 
開發者ID:Legostaev,項目名稱:xmlsec-gost,代碼行數:11,代碼來源:XMLSignatureTest.java

示例11: HMACSignatureAlgorithmTest

import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec; //導入依賴的package包/類
public HMACSignatureAlgorithmTest() throws Exception {
    //
    // If the BouncyCastle provider is not installed, then try to load it
    // via reflection.
    //
    if (Security.getProvider("BC") == null) {
        Constructor<?> cons = null;
        try {
            Class<?> c = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider");
            cons = c.getConstructor(new Class[] {});
        } catch (Exception e) {
            //ignore
        }
        if (cons != null) {
            Provider provider = (Provider)cons.newInstance();
            Security.insertProviderAt(provider, 2);
            bcInstalled = true;
        }
    }

    db = XMLUtils.createDocumentBuilder(false);
    // create common objects
    fac = XMLSignatureFactory.getInstance("DOM", new org.apache.jcp.xml.dsig.internal.dom.XMLDSigRI());
    withoutComments = fac.newCanonicalizationMethod
        (CanonicalizationMethod.INCLUSIVE, (C14NMethodParameterSpec) null);

    // Digest Methods
    sha1 = fac.newDigestMethod(DigestMethod.SHA1, null);

    hmacSha1 = fac.newSignatureMethod("http://www.w3.org/2000/09/xmldsig#hmac-sha1", null);
    hmacSha224 = fac.newSignatureMethod("http://www.w3.org/2001/04/xmldsig-more#hmac-sha224", null);
    hmacSha256 = fac.newSignatureMethod("http://www.w3.org/2001/04/xmldsig-more#hmac-sha256", null);
    hmacSha384 = fac.newSignatureMethod("http://www.w3.org/2001/04/xmldsig-more#hmac-sha384", null);
    hmacSha512 = fac.newSignatureMethod("http://www.w3.org/2001/04/xmldsig-more#hmac-sha512", null);
    ripemd160 = fac.newSignatureMethod("http://www.w3.org/2001/04/xmldsig-more#hmac-ripemd160", null);

    sks = new KeySelectors.SecretKeySelector("testkey".getBytes("ASCII"));
}
 
開發者ID:Legostaev,項目名稱:xmlsec-gost,代碼行數:39,代碼來源:HMACSignatureAlgorithmTest.java

示例12: dsig

import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec; //導入依賴的package包/類
public void dsig() throws Exception {

        XMLSignatureFactory fac = XMLSignatureFactory.getInstance
            ("DOM", new org.apache.jcp.xml.dsig.internal.dom.XMLDSigRI());
        long start = System.currentTimeMillis();
        for (int i = 0; i < 100; i++) {
            fac.newCanonicalizationMethod
                (CanonicalizationMethod.EXCLUSIVE, (C14NMethodParameterSpec) null);
        }
        long end = System.currentTimeMillis();
        long elapsed = end - start;
        if (log.isDebugEnabled()) {
            log.debug("Elapsed: " + elapsed);
            log.debug("dsig succeeded");
        }
    }
 
開發者ID:Legostaev,項目名稱:xmlsec-gost,代碼行數:17,代碼來源:Driver.java

示例13: SignedInfoTest

import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec; //導入依賴的package包/類
public SignedInfoTest() throws Exception {
    fac = XMLSignatureFactory.getInstance
        ("DOM", new org.apache.jcp.xml.dsig.internal.dom.XMLDSigRI());
    cm = fac.newCanonicalizationMethod
        (CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS,
         (C14NMethodParameterSpec) null);
    sm = fac.newSignatureMethod(SignatureMethod.DSA_SHA1, null);
    references = new ArrayList<Reference>();
    references.add(fac.newReference
                   ("http://www.sun.com/index.html",
                    fac.newDigestMethod(DigestMethod.SHA1, null)));
}
 
開發者ID:Legostaev,項目名稱:xmlsec-gost,代碼行數:13,代碼來源:SignedInfoTest.java

示例14: assinarDocumento

import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec; //導入依賴的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

示例15: testJsr105ReferenceUri

import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec; //導入依賴的package包/類
@Test
public void testJsr105ReferenceUri() throws Exception {
	String uri = FilenameUtils.getName(new File("foo bar.txt").toURI().toURL().getFile());

	KeyPair keyPair = generateKeyPair();

	DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
	documentBuilderFactory.setNamespaceAware(true);
	DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
	Document document = documentBuilder.newDocument();

	XMLSignatureFactory signatureFactory = XMLSignatureFactory.getInstance("DOM", new XMLDSigRI());

	XMLSignContext signContext = new DOMSignContext(keyPair.getPrivate(), document);

	byte[] externalDocument = "hello world".getBytes();
	MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
	messageDigest.update(externalDocument);
	byte[] documentDigestValue = messageDigest.digest();

	DigestMethod digestMethod = signatureFactory.newDigestMethod(DigestMethod.SHA1, null);
	Reference reference = signatureFactory.newReference(uri, digestMethod, null, null, null, documentDigestValue);

	SignatureMethod signatureMethod = signatureFactory.newSignatureMethod(SignatureMethod.RSA_SHA1, null);
	CanonicalizationMethod canonicalizationMethod = signatureFactory.newCanonicalizationMethod(
			CanonicalizationMethod.EXCLUSIVE_WITH_COMMENTS, (C14NMethodParameterSpec) null);
	javax.xml.crypto.dsig.SignedInfo signedInfo = signatureFactory.newSignedInfo(canonicalizationMethod,
			signatureMethod, Collections.singletonList(reference));

	javax.xml.crypto.dsig.XMLSignature xmlSignature = signatureFactory.newXMLSignature(signedInfo, null);

	xmlSignature.sign(signContext);
}
 
開發者ID:e-Contract,項目名稱:eid-applet,代碼行數:34,代碼來源:XmlSignatureServiceBeanTest.java


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