Examples of PrivateKeyType


Examples of org.w3._2002._03.xkms_.PrivateKeyType

        DocumentBuilder db = dbf.newDocumentBuilder();
        KeyPair keys = KeyTools.genKeys("1024", "RSA");                               
        RegisterResultType registerResultType = xKMSObjectFactory.createRegisterResultType();
        JAXBElement<RegisterResultType> registerResult = xKMSObjectFactory.createRegisterResult(registerResultType);
               
        PrivateKeyType privateKeyType1 = XKMSUtil.getEncryptedXMLFromPrivateKey( (RSAPrivateCrtKey) keys.getPrivate(), "This is total crap");
        registerResultType.setPrivateKey(privateKeyType1);
       
        Document registerResultDoc = db.newDocument();
        marshaller.marshal( registerResult, registerResultDoc );

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

        JAXBElement<RegisterResultType> registerResult2 = (JAXBElement<RegisterResultType>) unmarshaller.unmarshal(bais);
        registerResultType = registerResult2.getValue();
       
        PrivateKeyType privateKeyType2 = registerResultType.getPrivateKey();
        RSAPrivateKey privkey2 = XKMSUtil.getPrivateKeyFromEncryptedXML(privateKeyType2, "This is total crap");
        X509Certificate cert = CertTools.genSelfCert("CN=test", 10, null,privkey2, keys.getPublic(), "SHA1WithRSA", true);
        cert.verify(keys.getPublic());   
    }   
View Full Code Here

Examples of org.w3._2002._03.xkms_.PrivateKeyType

   * @return The Document with the encrypted key included.
   * @throws StringprepException if the shared secret doesn't conform with the SASLprep profile as specified in the XKMS specification.
   * @throws XMLEncryptionException if any other exception occurs during the processing.
   */
  public static PrivateKeyType getEncryptedXMLFromPrivateKey(RSAPrivateCrtKey rSAPrivateKey, String sharedSecret) throws StringprepException, XMLEncryptionException{
    PrivateKeyType privateKeyType = null;
    try{
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document rSAKeyPairDoc = db.newDocument();

        SecretKey sk = getSecretKeyFromPassphrase(sharedSecret,true, 24, KEY_PRIVATEKEYDATA);
       
        RSAKeyPairType rSAKeyPairType = xKMSObjectFactory.createRSAKeyPairType();
      
        rSAKeyPairType.setModulus(rSAPrivateKey.getModulus().toByteArray());
        rSAKeyPairType.setExponent(rSAPrivateKey.getPublicExponent().toByteArray());
        rSAKeyPairType.setP(rSAPrivateKey.getPrimeP().toByteArray());
        rSAKeyPairType.setQ(rSAPrivateKey.getPrimeQ().toByteArray());
        rSAKeyPairType.setDP(rSAPrivateKey.getPrimeExponentP().toByteArray());
        rSAKeyPairType.setDQ(rSAPrivateKey.getPrimeExponentQ().toByteArray());
        rSAKeyPairType.setInverseQ(rSAPrivateKey.getCrtCoefficient().toByteArray());
        rSAKeyPairType.setD(rSAPrivateKey.getPrivateExponent().toByteArray());

        JAXBElement<RSAKeyPairType> rSAKeyPair = xKMSObjectFactory.createRSAKeyPair(rSAKeyPairType);

    marshaller.marshal( rSAKeyPair, rSAKeyPairDoc );

    Document envelopedDoc = db.newDocument();
    Element unencryptedElement = envelopedDoc.createElement("PrivateKey");
    envelopedDoc.appendChild(unencryptedElement);
    Element node = (Element) envelopedDoc.adoptNode(rSAKeyPairDoc.getDocumentElement());
    unencryptedElement.appendChild(node);
   
        Element rootElement = envelopedDoc.getDocumentElement();
      
       
        XMLCipher xmlCipher =
            XMLCipher.getProviderInstance(ENCRYPTION_ALGORITHMURI,"BC");
        xmlCipher.init(XMLCipher.ENCRYPT_MODE, sk);

        EncryptedData encryptedData = xmlCipher.getEncryptedData();
        encryptedData.setMimeType("text/xml");
       
        xmlCipher.doFinal(envelopedDoc,rootElement,true);     

        JAXBElement unmarshalledData = (JAXBElement) unmarshaller.unmarshal(envelopedDoc.getDocumentElement().getFirstChild());
       
        EncryptedDataType encryptedDataType = (EncryptedDataType) unmarshalledData.getValue();
        privateKeyType = xKMSObjectFactory.createPrivateKeyType();
        privateKeyType.setEncryptedData(encryptedDataType);
       
    } catch (ParserConfigurationException e) {
      log.error("Error encryption private key", e);
      throw new XMLEncryptionException(e.getMessage(),e);
    } catch (XMLSecurityException e) {
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.