/** * Constructor for processing encrypted octets * * @param data The <code>CipherData</code> object to read the bytes from * @throws XMLEncryptionException {@link XMLEncryptionException} */ public XMLCipherInput(CipherData data) throws XMLEncryptionException { cipherData = data; mode = XMLCipher.DECRYPT_MODE; if (cipherData == null) { throw new XMLEncryptionException("CipherData is null"); } }
key = (SecretKey) cipher.decryptKey(ek, algorithm); } catch (XMLEncryptionException e) { LOG.debug(e.getMessage(), e);
/** {@inheritDoc} */ public void setCipherReference(CipherReference reference) throws XMLEncryptionException { if (cipherType == VALUE_TYPE) { throw new XMLEncryptionException( new UnsupportedOperationException(referenceMessage) ); } cipherReference = reference; }
/** {@inheritDoc} */ public void setCipherValue(CipherValue value) throws XMLEncryptionException { if (cipherType == REFERENCE_TYPE) { throw new XMLEncryptionException(new UnsupportedOperationException(valueMessage)); } cipherValue = value; }
/** * Returns an <code>EncryptedData</code> interface. Use this operation if * you want to load an <code>EncryptedData</code> structure from a DOM * structure and manipulate the contents. * * @param context the context <code>Document</code>. * @param element the <code>Element</code> that will be loaded * @throws XMLEncryptionException * @return the <code>EncryptedData</code> */ public EncryptedData loadEncryptedData(Document context, Element element) throws XMLEncryptionException { LOG.debug("Loading encrypted element..."); if (null == context) { throw new XMLEncryptionException("empty", "Context document unexpectedly null..."); } if (null == element) { throw new XMLEncryptionException("empty", "Element unexpectedly null..."); } if (cipherMode != DECRYPT_MODE) { throw new XMLEncryptionException("empty", "XMLCipher unexpectedly not in DECRYPT_MODE..."); } contextDocument = context; ed = factory.newEncryptedData(element); return ed; }
/** * Returns an <code>EncryptedKey</code> interface. Use this operation if * you want to load an <code>EncryptedKey</code> structure from a DOM * structure and manipulate the contents. * * @param context the context <code>Document</code>. * @param element the <code>Element</code> that will be loaded * @return the <code>EncryptedKey</code> * @throws XMLEncryptionException */ public EncryptedKey loadEncryptedKey(Document context, Element element) throws XMLEncryptionException { LOG.debug("Loading encrypted key..."); if (null == context) { throw new XMLEncryptionException("empty", "Context document unexpectedly null..."); } if (null == element) { throw new XMLEncryptionException("empty", "Context document unexpectedly null..."); } if (cipherMode != UNWRAP_MODE && cipherMode != DECRYPT_MODE) { throw new XMLEncryptionException("empty", "XMLCipher unexpectedly not in UNWRAP_MODE or DECRYPT_MODE..." ); } contextDocument = context; ek = factory.newEncryptedKey(element); return ek; }
/** * Returns an <code>EncryptedData</code> interface. Use this operation if * you want to have full control over the serialization of the element * or element content. * * This does not change the source document in any way. * * @param context the context <code>Document</code>. * @param type a URI identifying type information about the plaintext form * of the encrypted content (may be <code>null</code>) * @param serializedData the serialized data * @return the <code>EncryptedData</code> * @throws Exception */ public EncryptedData encryptData( Document context, String type, InputStream serializedData ) throws Exception { LOG.debug("Encrypting element..."); if (null == context) { throw new XMLEncryptionException("empty", "Context document unexpectedly null..."); } if (null == serializedData) { throw new XMLEncryptionException("empty", "Serialized data unexpectedly null..."); } if (cipherMode != ENCRYPT_MODE) { throw new XMLEncryptionException("empty", "XMLCipher unexpectedly not in ENCRYPT_MODE..."); } return encryptData(context, null, type, serializedData); }
/** * Constructor for processing encrypted octets * * @param input The <code>EncryptedType</code> object to read * the bytes from. * @throws XMLEncryptionException {@link XMLEncryptionException} */ public XMLCipherInput(EncryptedType input) throws XMLEncryptionException { cipherData = input == null ? null : input.getCipherData(); mode = XMLCipher.DECRYPT_MODE; if (cipherData == null) { throw new XMLEncryptionException("CipherData is null"); } }
/** * * @param element * @return the <code>Node</code> as a result of the decrypt operation. * @throws XMLEncryptionException */ private Document decryptElementContent(Element element) throws XMLEncryptionException { Element e = (Element) element.getElementsByTagNameNS( EncryptionConstants.EncryptionSpecNS, EncryptionConstants._TAG_ENCRYPTEDDATA ).item(0); if (null == e) { throw new XMLEncryptionException("empty", "No EncryptedData child element."); } return decryptElement(e); }
private Cipher constructCipher(String algorithm, String digestAlgorithm, Exception nsae) throws XMLEncryptionException { if (!XMLCipher.RSA_OAEP.equals(algorithm)) { throw new XMLEncryptionException(nsae); throw new XMLEncryptionException(ex); throw new XMLEncryptionException(ex); throw new XMLEncryptionException(ex); throw new XMLEncryptionException(ex); throw new XMLEncryptionException(nsae);
LOG.debug("Processing source document..."); if (null == context) { throw new XMLEncryptionException("empty", "Context document unexpectedly null..."); throw new XMLEncryptionException("empty", "Source document unexpectedly null..."); break; default: throw new XMLEncryptionException(new IllegalStateException());
LOG.debug("Encrypting element..."); if (null == context) { throw new XMLEncryptionException("empty", "Context document unexpectedly null..."); throw new XMLEncryptionException("empty", "Element unexpectedly null..."); throw new XMLEncryptionException("empty", "XMLCipher unexpectedly not in ENCRYPT_MODE...");
LOG.debug("Processing source element..."); if (null == context) { throw new XMLEncryptionException("empty", "Context document unexpectedly null..."); throw new XMLEncryptionException("empty", "Source element unexpectedly null..."); break; default: throw new XMLEncryptionException(new IllegalStateException());
/** * Construct a Cipher object */ private Cipher constructCipher(String algorithm, String digestAlgorithm) throws XMLEncryptionException { String jceAlgorithm = JCEMapper.translateURItoJCEID(algorithm); LOG.debug("JCE Algorithm = {}", jceAlgorithm); Cipher c; try { if (requestedJCEProvider == null) { c = Cipher.getInstance(jceAlgorithm); } else { c = Cipher.getInstance(jceAlgorithm, requestedJCEProvider); } } catch (NoSuchAlgorithmException nsae) { // Check to see if an RSA OAEP MGF-1 with SHA-1 algorithm was requested // Some JDKs don't support RSA/ECB/OAEPPadding c = constructCipher(algorithm, digestAlgorithm, nsae); } catch (NoSuchProviderException nspre) { throw new XMLEncryptionException(nspre); } catch (NoSuchPaddingException nspae) { throw new XMLEncryptionException(nspae); } return c; }
/** * Encrypts an <code>Element</code> and replaces it with its encrypted * counterpart in the context <code>Document</code>, that is, the * <code>Document</code> specified when one calls * {@link #getInstance(String) getInstance}. * * @param element the <code>Element</code> to encrypt. * @return the context <code>Document</code> with the encrypted * <code>Element</code> having replaced the source <code>Element</code>. * @throws Exception */ private Document encryptElement(Element element) throws Exception{ LOG.debug("Encrypting element..."); if (null == element) { throw new XMLEncryptionException("empty", "Element unexpectedly null..."); } if (cipherMode != ENCRYPT_MODE) { throw new XMLEncryptionException("empty", "XMLCipher unexpectedly not in ENCRYPT_MODE..."); } if (algorithm == null) { throw new XMLEncryptionException("empty", "XMLCipher instance without transformation specified"); } encryptData(contextDocument, element, false); Element encryptedElement = factory.toElement(ed); Node sourceParent = element.getParentNode(); sourceParent.replaceChild(encryptedElement, element); return contextDocument; }
throw new XMLEncryptionException(e); } catch (IOException e) { throw new XMLEncryptionException(e);
LOG.debug("Encrypting element content..."); if (null == element) { throw new XMLEncryptionException("empty", "Element unexpectedly null..."); throw new XMLEncryptionException("empty", "XMLCipher unexpectedly not in ENCRYPT_MODE..."); throw new XMLEncryptionException("empty", "XMLCipher instance without transformation specified");
/** * @param element * @return a new CipherReference * @throws XMLEncryptionException * */ CipherReference newCipherReference(Element element) throws XMLEncryptionException { Attr uriAttr = element.getAttributeNodeNS(null, EncryptionConstants._ATT_URI); CipherReference result = new CipherReferenceImpl(uriAttr); // Find any Transforms NodeList transformsElements = element.getElementsByTagNameNS( EncryptionConstants.EncryptionSpecNS, EncryptionConstants._TAG_TRANSFORMS); Element transformsElement = (Element) transformsElements.item(0); if (transformsElement != null) { LOG.debug("Creating a DSIG based Transforms element"); try { result.setTransforms(new TransformsImpl(transformsElement)); } catch (XMLSignatureException xse) { throw new XMLEncryptionException(xse); } catch (InvalidTransformException ite) { throw new XMLEncryptionException(ite); } catch (XMLSecurityException xse) { throw new XMLEncryptionException(xse); } } return result; }
v.add(byteArrayOutputStream.createInputStream()); } catch (IOException e) { throw new XMLEncryptionException(e);
throw new XMLEncryptionException(se); } catch (ParserConfigurationException pce) { throw new XMLEncryptionException(pce); } catch (IOException ioe) { throw new XMLEncryptionException(ioe); } finally { if (db != null) {