@Test public void testEncryptDocument_EmptyRuleExecutionContainer() { logger.debug("NOT ENCRYPTED--> " + c32); String encrypted = null; try { List<RuleExecutionResponse> list = new LinkedList<RuleExecutionResponse>(); RuleExecutionContainer container = new RuleExecutionContainer(); container.setExecutionResponseList(list); encrypted = documentEncrypter.encryptDocument( EncryptTool.generateKeyEncryptionKey(), c32, container); } catch (Exception e) { logger.error(e.getMessage(), e); } logger.debug("ENCRYPTED--> " + encrypted); assertNotEquals(c32, encrypted); assertNull(encrypted); }
@Override public String encryptDocument(Key deSedeEncryptKey, String document, RuleExecutionContainer ruleExecutionContainer) { Document xmlDocument = null; String xmlString = null; boolean encryptDoc = false; for (RuleExecutionResponse response : ruleExecutionContainer .getExecutionResponseList()) { if (response.getDocumentObligationPolicy().equals(ObligationPolicyDocument.ENCRYPT)) { encryptDoc = true; break; } } if (encryptDoc) { try { xmlDocument = documentXmlConverter.loadDocument(document); Key aesSymmetricKey = EncryptTool.generateDataEncryptionKey(); String algorithmURI = XMLCipher.TRIPLEDES_KeyWrap; XMLCipher keyCipher = XMLCipher.getInstance(algorithmURI); keyCipher.init(XMLCipher.WRAP_MODE, deSedeEncryptKey); EncryptedKey encryptedKey = keyCipher.encryptKey(xmlDocument, aesSymmetricKey); Element rootElement = xmlDocument.getDocumentElement(); encryptElement(xmlDocument, aesSymmetricKey, encryptedKey, rootElement); xmlString = documentXmlConverter .convertXmlDocToString(xmlDocument); } catch (Exception e) { logger.error(e.getMessage(), e); throw new DS4PException(e.toString(), e); } } return xmlString; }
DocumentEncrypterImpl implements DocumentEncrypter { @Override public String encryptDocument(Key deSedeEncryptKey, String document, RuleExecutionContainer ruleExecutionContainer) { Document xmlDocument = null; String xmlString = null; boolean encryptDoc = false; for (RuleExecutionResponse response : ruleExecutionContainer .getExecutionResponseList()) { if (response.getDocumentObligationPolicy().equals(ObligationPolicyDocument.ENCRYPT)) { encryptDoc = true; break; } } if (encryptDoc) { try { xmlDocument = documentXmlConverter.loadDocument(document); Key aesSymmetricKey = EncryptTool.generateDataEncryptionKey(); String algorithmURI = XMLCipher.TRIPLEDES_KeyWrap; XMLCipher keyCipher = XMLCipher.getInstance(algorithmURI); keyCipher.init(XMLCipher.WRAP_MODE, deSedeEncryptKey); EncryptedKey encryptedKey = keyCipher.encryptKey(xmlDocument, aesSymmetricKey); Element rootElement = xmlDocument.getDocumentElement(); encryptElement(xmlDocument, aesSymmetricKey, encryptedKey, rootElement); xmlString = documentXmlConverter .convertXmlDocToString(xmlDocument); } catch (Exception e) { logger.error(e.getMessage(), e); throw new DS4PException(e.toString(), e); } } return xmlString; } }
DocumentEncrypterImpl implements DocumentEncrypter { @Override public String encryptDocument(Key deSedeEncryptKey, String document, RuleExecutionContainer ruleExecutionContainer) { Document xmlDocument = null; String xmlString = null; boolean encryptDoc = false; for (RuleExecutionResponse response : ruleExecutionContainer .getExecutionResponseList()) { if (response.getDocumentObligationPolicy().equals(ObligationPolicyDocument.ENCRYPT)) { encryptDoc = true; break; } } if (encryptDoc) { try { xmlDocument = documentXmlConverter.loadDocument(document); Key aesSymmetricKey = EncryptTool.generateDataEncryptionKey(); String algorithmURI = XMLCipher.TRIPLEDES_KeyWrap; XMLCipher keyCipher = XMLCipher.getInstance(algorithmURI); keyCipher.init(XMLCipher.WRAP_MODE, deSedeEncryptKey); EncryptedKey encryptedKey = keyCipher.encryptKey(xmlDocument, aesSymmetricKey); Element rootElement = xmlDocument.getDocumentElement(); encryptElement(xmlDocument, aesSymmetricKey, encryptedKey, rootElement); xmlString = documentXmlConverter .convertXmlDocToString(xmlDocument); } catch (Exception e) { logger.error(e.getMessage(), e); throw new DS4PException(e.toString(), e); } } return xmlString; } DocumentEncrypterImpl();  DocumentEncrypterImpl(DocumentXmlConverter documentXmlConverter); }
DocumentEncrypterImpl implements DocumentEncrypter { @Override public String encryptDocument(Key deSedeEncryptKey, String document, RuleExecutionContainer ruleExecutionContainer) { Document xmlDocument = null; String xmlString = null; boolean encryptDoc = false; for (RuleExecutionResponse response : ruleExecutionContainer .getExecutionResponseList()) { if (response.getDocumentObligationPolicy().equals(ObligationPolicyDocument.ENCRYPT)) { encryptDoc = true; break; } } if (encryptDoc) { try { xmlDocument = documentXmlConverter.loadDocument(document); Key aesSymmetricKey = EncryptTool.generateDataEncryptionKey(); String algorithmURI = XMLCipher.TRIPLEDES_KeyWrap; XMLCipher keyCipher = XMLCipher.getInstance(algorithmURI); keyCipher.init(XMLCipher.WRAP_MODE, deSedeEncryptKey); EncryptedKey encryptedKey = keyCipher.encryptKey(xmlDocument, aesSymmetricKey); Element rootElement = xmlDocument.getDocumentElement(); encryptElement(xmlDocument, aesSymmetricKey, encryptedKey, rootElement); xmlString = documentXmlConverter .convertXmlDocToString(xmlDocument); } catch (Exception e) { logger.error(e.getMessage(), e); throw new DS4PException(e.toString(), e); } } return xmlString; } DocumentEncrypterImpl();  DocumentEncrypterImpl(DocumentXmlConverter documentXmlConverter); @Override String encryptDocument(Key deSedeEncryptKey, String document,
			RuleExecutionContainer ruleExecutionContainer); }
DocumentEncrypterImpl implements DocumentEncrypter { @Override public String encryptDocument(Key deSedeEncryptKey, String document, RuleExecutionContainer ruleExecutionContainer) { Document xmlDocument = null; String xmlString = null; boolean encryptDoc = false; for (RuleExecutionResponse response : ruleExecutionContainer .getExecutionResponseList()) { if (response.getDocumentObligationPolicy().equals(ObligationPolicyDocument.ENCRYPT)) { encryptDoc = true; break; } } if (encryptDoc) { try { xmlDocument = documentXmlConverter.loadDocument(document); Key aesSymmetricKey = EncryptTool.generateDataEncryptionKey(); String algorithmURI = XMLCipher.TRIPLEDES_KeyWrap; XMLCipher keyCipher = XMLCipher.getInstance(algorithmURI); keyCipher.init(XMLCipher.WRAP_MODE, deSedeEncryptKey); EncryptedKey encryptedKey = keyCipher.encryptKey(xmlDocument, aesSymmetricKey); Element rootElement = xmlDocument.getDocumentElement(); encryptElement(xmlDocument, aesSymmetricKey, encryptedKey, rootElement); xmlString = documentXmlConverter .convertXmlDocToString(xmlDocument); } catch (Exception e) { logger.error(e.getMessage(), e); throw new DS4PException(e.toString(), e); } } return xmlString; } DocumentEncrypterImpl();  DocumentEncrypterImpl(DocumentXmlConverter documentXmlConverter); @Override String encryptDocument(Key deSedeEncryptKey, String document,
			RuleExecutionContainer ruleExecutionContainer);  }