Examples of RSAKeyValueType


Examples of org.picketlink.identity.xmlsec.w3.xmldsig.RSAKeyValueType

        StaxParserUtil.validate(startElement, WSTrustConstants.XMLDSig.RSA_KEYVALUE);

        XMLEvent xmlEvent = null;
        String tag = null;

        RSAKeyValueType rsaKeyValue = new RSAKeyValueType();

        while (xmlEventReader.hasNext()) {
            xmlEvent = StaxParserUtil.peek(xmlEventReader);
            if (xmlEvent instanceof EndElement) {
                tag = StaxParserUtil.getEndElementName((EndElement) xmlEvent);
                if (tag.equals(WSTrustConstants.XMLDSig.RSA_KEYVALUE)) {
                    xmlEvent = StaxParserUtil.getNextEndElement(xmlEventReader);
                    break;
                } else
                    throw logger.parserUnknownEndElement(tag);
            }

            startElement = (StartElement) xmlEvent;
            tag = StaxParserUtil.getStartElementName(startElement);
            if (tag.equals(WSTrustConstants.XMLDSig.MODULUS)) {
                startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
                String text = StaxParserUtil.getElementText(xmlEventReader);
                rsaKeyValue.setModulus(text.getBytes());
            } else if (tag.equals(WSTrustConstants.XMLDSig.EXPONENT)) {
                startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
                String text = StaxParserUtil.getElementText(xmlEventReader);
                rsaKeyValue.setExponent(text.getBytes());
            } else
                throw logger.parserUnknownTag(tag, startElement.getLocation());
        }
        return rsaKeyValue;
    }
View Full Code Here

Examples of org.picketlink.identity.xmlsec.w3.xmldsig.RSAKeyValueType

    private void writeKeyValueType(KeyValueType type) throws ProcessingException {
        StaxUtil.writeStartElement(writer, WSTrustConstants.XMLDSig.DSIG_PREFIX, WSTrustConstants.XMLDSig.KEYVALUE,
                WSTrustConstants.DSIG_NS);
        StaxUtil.writeNameSpace(writer, WSTrustConstants.XMLDSig.DSIG_PREFIX, WSTrustConstants.DSIG_NS);
        if (type instanceof RSAKeyValueType) {
            RSAKeyValueType rsaKeyValue = (RSAKeyValueType) type;
            StaxUtil.writeRSAKeyValueType(writer,rsaKeyValue);
        } else if(type instanceof DSAKeyValueType) {
            DSAKeyValueType dsaKeyValue = (DSAKeyValueType)type;
            StaxUtil.writeDSAKeyValueType(writer, dsaKeyValue);
        }
View Full Code Here

Examples of org.picketlink.identity.xmlsec.w3.xmldsig.RSAKeyValueType

        StaxParserUtil.validate(startElement, WSTrustConstants.XMLDSig.RSA_KEYVALUE);

        XMLEvent xmlEvent = null;
        String tag = null;

        RSAKeyValueType rsaKeyValue = new RSAKeyValueType();

        while (xmlEventReader.hasNext()) {
            xmlEvent = StaxParserUtil.peek(xmlEventReader);
            if (xmlEvent instanceof EndElement) {
                tag = StaxParserUtil.getEndElementName((EndElement) xmlEvent);
                if (tag.equals(WSTrustConstants.XMLDSig.RSA_KEYVALUE)) {
                    xmlEvent = StaxParserUtil.getNextEndElement(xmlEventReader);
                    break;
                } else
                    throw logger.parserUnknownEndElement(tag);
            }

            startElement = (StartElement) xmlEvent;
            tag = StaxParserUtil.getStartElementName(startElement);
            if (tag.equals(WSTrustConstants.XMLDSig.MODULUS)) {
                startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
                String text = StaxParserUtil.getElementText(xmlEventReader);
                rsaKeyValue.setModulus(text.getBytes());
            } else if (tag.equals(WSTrustConstants.XMLDSig.EXPONENT)) {
                startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
                String text = StaxParserUtil.getElementText(xmlEventReader);
                rsaKeyValue.setExponent(text.getBytes());
            } else
                throw logger.parserUnknownTag(tag, startElement.getLocation());
        }
        return rsaKeyValue;
    }
View Full Code Here

Examples of org.picketlink.identity.xmlsec.w3.xmldsig.RSAKeyValueType

        assertNotNull(doc.getDocumentElement());
       
        Element rsaEl = (Element) doc.getElementsByTagName("ds:RSAKeyValue").item(0);
        assertNotNull(rsaEl);
       
        RSAKeyValueType rsa = XMLSignatureUtil.getRSAKeyValue(rsaEl);
        assertNotNull(rsa);
        assertNotNull(rsa.getModulus());
        assertNotNull(rsa.getExponent());
       
        System.out.println(rsa);
       
        RSAPublicKey publicKey = rsa.convertToPublicKey();
        assertNotNull(publicKey);
    }
View Full Code Here

Examples of org.picketlink.identity.xmlsec.w3.xmldsig.RSAKeyValueType

        // if the key is public, KeyInfo should either contain an encoded certificate or an encoded public key.
        else if (WSTrustConstants.KEY_TYPE_PUBLIC.equals(keyType)) {
            // if the public key has been used as proof, we should be able to retrieve it from KeyValueType.
            if (usePublicKey == true) {
                KeyValueType keyValue = (KeyValueType) keyInfo.getContent().get(0);
                RSAKeyValueType rsaKeyValue = (RSAKeyValueType) keyValue;

                // reconstruct the public key and check if it matches the public key of the provided certificate.
                BigInteger modulus = new BigInteger(1, Base64.decode(new String(rsaKeyValue.getModulus())));
                BigInteger exponent = new BigInteger(1, Base64.decode(new String(rsaKeyValue.getExponent())));
                KeyFactory factory = KeyFactory.getInstance("RSA");
                RSAPublicKeySpec spec = new RSAPublicKeySpec(modulus, exponent);
                RSAPublicKey genKey = (RSAPublicKey) factory.generatePublic(spec);
                assertEquals("Invalid public key", certificate.getPublicKey(), genKey);
            }
View Full Code Here

Examples of org.picketlink.identity.xmlsec.w3.xmldsig.RSAKeyValueType

     * @param element
     * @return
     * @throws ProcessingException
     */
    public static RSAKeyValueType getRSAKeyValue(Element element) throws ParsingException {
        RSAKeyValueType rsa = new RSAKeyValueType();
        NodeList nl  = element.getChildNodes();
        int length = nl.getLength();

        for(int i = 0; i < length; i++){
            Node node  = nl.item(i);
            if(node instanceof Element){
                Element childElement = (Element) node;
                String tag = childElement.getLocalName();
               
                byte[] text = childElement.getTextContent().getBytes();
               
                if(WSTrustConstants.XMLDSig.MODULUS.equals(tag)){
                    rsa.setModulus(text);
                } else if(WSTrustConstants.XMLDSig.EXPONENT.equals(tag)){
                    rsa.setExponent(text);
                }
            }
        }

        return rsa;
View Full Code Here

Examples of org.picketlink.identity.xmlsec.w3.xmldsig.RSAKeyValueType

        if (key instanceof RSAPublicKey) {
            RSAPublicKey pubKey = (RSAPublicKey) key;
            byte[] modulus = pubKey.getModulus().toByteArray();
            byte[] exponent = pubKey.getPublicExponent().toByteArray();

            RSAKeyValueType rsaKeyValue = new RSAKeyValueType();
            rsaKeyValue.setModulus(Base64.encodeBytes(modulus).getBytes());
            rsaKeyValue.setExponent(Base64.encodeBytes(exponent).getBytes());
            return rsaKeyValue;
        } else if (key instanceof DSAPublicKey) {
            DSAPublicKey pubKey = (DSAPublicKey) key;
            byte[] P = pubKey.getParams().getP().toByteArray();
            byte[] Q = pubKey.getParams().getQ().toByteArray();
View Full Code Here

Examples of org.w3._2000._09.xmldsig_.RSAKeyValueType

            RegisterResultType registerResultType = null;
            if(genKeys == null){
              registerResultType = getXKMSInvoker().register(registerRequestType, clientCert, privateKey, password, null, keyBindingId);
            }else{
              KeyInfoType keyInfoType = sigFactory.createKeyInfoType();
                RSAKeyValueType rsaKeyValueType = sigFactory.createRSAKeyValueType();
                rsaKeyValueType.setExponent(((RSAPublicKey) genKeys.getPublic()).getPublicExponent().toByteArray());
                rsaKeyValueType.setModulus(((RSAPublicKey) genKeys.getPublic()).getModulus().toByteArray());
                JAXBElement<RSAKeyValueType> rsaKeyValue = sigFactory.createRSAKeyValue(rsaKeyValueType);
                keyInfoType.getContent().add(rsaKeyValue);
               
                prototypeKeyBinding.setKeyInfo(keyInfoType);
             
View Full Code Here

Examples of org.w3._2000._09.xmldsig_.RSAKeyValueType

     }

     if(req.getRespondWith().contains(XKMSConstants.RESPONDWITH_KEYVALUE)){
       if(cert.getPublicKey() instanceof RSAPublicKey){ 
         RSAPublicKey pubKey = (RSAPublicKey) cert.getPublicKey();       
         RSAKeyValueType rSAKeyValueType = sigFactory.createRSAKeyValueType();
         rSAKeyValueType.setModulus(pubKey.getModulus().toByteArray());
         rSAKeyValueType.setExponent(pubKey.getPublicExponent().toByteArray());
         KeyValueType keyValue = sigFactory.createKeyValueType();
         keyValue.getContent().add(sigFactory.createRSAKeyValue(rSAKeyValueType));
         keyInfoType.getContent().add(sigFactory.createKeyValue(keyValue));                         
       }else{
         log.error(intres.getLocalizedMessage("xkms.onlyrsakeysupported"));        
View Full Code Here

Examples of org.w3._2000._09.xmldsig_.RSAKeyValueType

        useKeyWithType.setIdentifier("CN=Test Testarsson");
       
        registerRequestType.getRespondWith().add(XKMSConstants.RESPONDWITH_X509CHAIN);
     
        KeyInfoType keyInfoType = sigFactory.createKeyInfoType();
        RSAKeyValueType rsaKeyValueType = sigFactory.createRSAKeyValueType();
        rsaKeyValueType.setExponent(((RSAPublicKey) keys.getPublic()).getPublicExponent().toByteArray());
        rsaKeyValueType.setModulus(((RSAPublicKey) keys.getPublic()).getModulus().toByteArray());
        JAXBElement<RSAKeyValueType> rsaKeyValue = sigFactory.createRSAKeyValue(rsaKeyValueType);
        keyInfoType.getContent().add(rsaKeyValue);
        PrototypeKeyBindingType prototypeKeyBindingType = xKMSObjectFactory.createPrototypeKeyBindingType();
        prototypeKeyBindingType.getUseKeyWith().add(useKeyWithType);
        prototypeKeyBindingType.setKeyInfo(keyInfoType);
        prototypeKeyBindingType.setId("100231");
        registerRequestType.setPrototypeKeyBinding(prototypeKeyBindingType);               
        JAXBElement<RegisterRequestType> registerRequest = xKMSObjectFactory.createRegisterRequest(registerRequestType);

        Document registerRequestDoc = db.newDocument();
        marshaller.marshal( registerRequest, registerRequestDoc );

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        XMLUtils.outputDOM(registerRequestDoc, baos);
        log.debug("XMLUtils.outputDOM: " + baos.toString());
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());

        JAXBElement<RegisterRequestType> registerRequest2 = (JAXBElement<RegisterRequestType>) unmarshaller.unmarshal(bais);
        registerRequestType = registerRequest2.getValue();
       
        RSAKeyValueType rSAKeyValueType  = (RSAKeyValueType) ((JAXBElement) registerRequestType.getPrototypeKeyBinding().getKeyInfo().getContent().get(0)).getValue();       
        RSAPublicKeySpec rSAPublicKeySpec = new RSAPublicKeySpec(new BigInteger(rSAKeyValueType.getModulus()), new BigInteger(rSAKeyValueType.getExponent()));       
        RSAPublicKey rSAPublicKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(rSAPublicKeySpec);
       
        X509Certificate cert = CertTools.genSelfCert("CN=test", 10, null,keys.getPrivate(), rSAPublicKey, "SHA1WithRSA", true);
       
        cert.verify(rSAPublicKey)
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.