Package javax.xml.crypto.dsig

Examples of javax.xml.crypto.dsig.SignatureMethod


            final C14NMethodParameterSpec spec = null;
            final CanonicalizationMethod canonicalMethod =
                    signatureFactory.newCanonicalizationMethod(CanonicalizationMethod.EXCLUSIVE,spec);
            DigestMethod digestMethod;
            digestMethod = signatureFactory.newDigestMethod(DigestMethod.SHA1, null);
            SignatureMethod signatureMethod;
            signatureMethod = signatureFactory.newSignatureMethod(SignatureMethod.RSA_SHA1, null);
           
            //Note : Signature algorithm parameters null for now , fix me.
           
            final ArrayList<Transform> transformList = new ArrayList<Transform>();
View Full Code Here


    }

    public boolean validate(XMLValidateContext xMLValidateContext) throws XMLSignatureException {

        SignatureMethod sm;
        if (xMLValidateContext == null) {
            throw new NullPointerException("validateContext cannot be null");
        }
       

        //List allReferences = new ArrayList(signedInfo.getReferences());

       
        SignedInfo si = getSignedInfo();
        List refList = si.getReferences();
        for (int i = 0, size = refList.size(); i < size; i++) {
            Reference ref = (Reference) refList.get(i);
            byte[] originalDigest = ref.getDigestValue();
            ref.digest(xMLValidateContext);
            byte[] calculatedDigest = ref.getDigestValue();
            if ( ! Arrays.equals(originalDigest, calculatedDigest) ) {
                logger.log(Level.SEVERE, LogStringsMessages.WSS_1713_SIGNATURE_VERIFICATION_EXCEPTION("Signature digest values mismatch"));
                throw new XMLSignatureException(LogStringsMessages.WSS_1713_SIGNATURE_VERIFICATION_EXCEPTION("Signature digest values mismatch"));

            }
        }
        si.setSignedInfo(_streamSI);

        // si.setCanonicalizedSI(signedInfoBytes);
       

        KeySelectorResult keySelectoResult = null;
        try {
            sm = si.getSignatureMethod();
            if(verificationKey == null){
                keySelectoResult = xMLValidateContext.getKeySelector().select(getKeyInfo(),KeySelector.Purpose.VERIFY,sm,xMLValidateContext);
                verificationKey = keySelectoResult.getKey();
            }
            if (verificationKey == null) {
                throw new XMLSignatureException("The KeySelector"+ xMLValidateContext.getKeySelector()+ " did not " +
                          "find the key used for signature verification");
            }

            if(_sp == null){
                _sp = new SignatureProcessor();
            }

            try {
                String signatureAlgo = sm.getAlgorithm();
                String algo = getRSASignatureAlgorithm(signatureAlgo);
                if (algo != null) {
                    return _sp.verifyRSASignature(verificationKey, si, getSignatureValue().getValue(), algo);
                } else if (signatureAlgo.equals(SignatureMethod.DSA_SHA1)) {
                    return _sp.verifyDSASignature(verificationKey, si, getSignatureValue().getValue());
                } else if (signatureAlgo.equals(SignatureMethod.HMAC_SHA1)) {
                    SignatureMethodParameterSpec params = (SignatureMethodParameterSpec)sm.getParameterSpec();

                    int outputLength = -1;

                    if (params != null) {
                        if (!(params instanceof HMACParameterSpec)) {
View Full Code Here

    public List getObjects() {
        return null;
    }

    public void sign(XMLSignContext xMLSignContext) throws MarshalException, XMLSignatureException {
        SignatureMethod sm;
        if (xMLSignContext == null) {
            throw new NullPointerException("signContext cannot be null");
        }
       
        //List allReferences = new ArrayList(signedInfo.getReferences());
        SignedInfo si = getSignedInfo();
        List refList = si.getReferences();
        for (int i = 0, size = refList.size(); i < size; i++) {
            Reference ref = (Reference) refList.get(i);
            ref.digest(xMLSignContext);
        }


        Key signingKey = null;
        KeySelectorResult keySelectoResult = null;
        try {
            sm = si.getSignatureMethod();
            keySelectoResult = xMLSignContext.getKeySelector().select(getKeyInfo(),KeySelector.Purpose.SIGN,sm,xMLSignContext);
            signingKey = keySelectoResult.getKey();
            if (signingKey == null) {
                throw new XMLSignatureException("The KeySelector"+ xMLSignContext.getKeySelector()+ " did not " +
                          "find the key used for signing");
            }
        } catch (KeySelectorException kse) {
            throw new XMLSignatureException("Cannot find signing key", kse);
        }

        if(_sp == null){
            try {
                JAXBContext jc = JAXBUtil.getJAXBContext();
                _sp = new SignatureProcessor();
                _sp.setJAXBContext(jc);
                _sp.setCryptoContext(xMLSignContext);
            } catch (Exception ex) {
                throw new XMLSignatureException(ex);
            }
        }

        String signatureAlgo = sm.getAlgorithm();
        //SignatureValue sv=getSignatureValue();
        String algo = getRSASignatureAlgorithm(signatureAlgo);
        if(algo != null){
             try {
                com.sun.xml.ws.security.opt.crypto.dsig.SignatureValue sigValue = new com.sun.xml.ws.security.opt.crypto.dsig.SignatureValue();
                sigValue.setValue(_sp.performRSASign(signingKey,signedInfo,algo));
                setSignatureValue(sigValue);
                //((SignatureValueType)getSignatureValue()).setValue(_sp.performRSASign(signingKey,signedInfo));
                //((SignatureValueType)sv).setValue(_sp.performRSASign(signingKey,signedInfo));
            } catch (InvalidKeyException ex) {
                throw new XMLSignatureException(ex);
            }
        } else if(signatureAlgo.equals(SignatureMethod.DSA_SHA1)){
            try {
                com.sun.xml.ws.security.opt.crypto.dsig.SignatureValue sigValue = new com.sun.xml.ws.security.opt.crypto.dsig.SignatureValue();
                sigValue.setValue(_sp.performDSASign(signingKey,signedInfo));
                setSignatureValue(sigValue);
               
                //((SignatureValueType)sv).setValue(_sp.performDSASign(signingKey,signedInfo));

            } catch (InvalidKeyException ex) {
                throw new XMLSignatureException(ex);
            }

        } else if ( signatureAlgo.equals(SignatureMethod.HMAC_SHA1)) {
            SignatureMethodParameterSpec params = (SignatureMethodParameterSpec)sm.getParameterSpec();
            int outputLength = -1;
            if (params != null) {
                if (!(params instanceof HMACParameterSpec)) {
                    throw new XMLSignatureException
                              ("SignatureMethodParameterSpec must be of type HMACParameterSpec");
View Full Code Here

        if(!fpContext.getDisableIncPrefix()){
            List contentList = setInclusiveNamespaces((ExcC14NParameterSpec)spec);
            ((com.sun.xml.ws.security.opt.crypto.dsig.CanonicalizationMethod)canonicalMethod).setContent(contentList);
        }
       
        SignatureMethod signatureMethod = signatureFactory.newSignatureMethod(keyAlgo, null);
        //Note : Signature algorithm parameters null for now , fix me.
        SignedInfo signedInfo = signatureFactory.newSignedInfo(canonicalMethod,signatureMethod,
                generateReferenceList(cloneList, signatureFactory, fpContext, false), null);
        //Note : Id is now null
        return signedInfo;
View Full Code Here

TOP

Related Classes of javax.xml.crypto.dsig.SignatureMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.