Java 类org.apache.camel.converter.crypto.CryptoDataFormat 实例源码

项目:Camel    文件:CryptoDataFormatAutoConfiguration.java   
@Bean
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(CryptoDataFormat.class)
public CryptoDataFormat configureCryptoDataFormat(
        CamelContext camelContext,
        CryptoDataFormatConfiguration configuration) throws Exception {
    CryptoDataFormat dataformat = new CryptoDataFormat();
    if (dataformat instanceof CamelContextAware) {
        ((CamelContextAware) dataformat).setCamelContext(camelContext);
    }
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null,
            false);
    IntrospectionSupport.setProperties(camelContext,
            camelContext.getTypeConverter(), dataformat, parameters);
    return dataformat;
}
项目:camel-cookbook-examples    文件:EncryptionDynamicRoute.java   
@Override
public void configure() throws Exception {
    final CryptoDataFormat crypto = new CryptoDataFormat("DES", null);

    from("direct:encrypt")
        .process(new Processor() {
            @Override
            public void process(Exchange exchange) throws Exception {
                Registry registry = exchange.getContext().getRegistry();
                Message in = exchange.getIn();
                Key key = registry.lookupByNameAndType("shared_" + in.getHeader("system"), Key.class);
                in.setHeader(CryptoDataFormat.KEY, key);
            }
        })
        .log("Encrypting message: ${body} using ${header[CamelCryptoKey]}")
        .marshal(crypto)
        .log("Message encrypted: ${body}")
        .to("direct:decrypt");

    from("direct:decrypt")
        .log("Decrypting message: ${body} using ${header[CamelCryptoKey]}")
        .unmarshal(crypto)
        .log("Message decrypted: ${body}")
        .to("mock:decrypted");
}
项目:camel-cookbook-examples    文件:EncryptionRoute.java   
@Override
public void configure() throws Exception {
    CryptoDataFormat sharedKeyCrypto = new CryptoDataFormat("DES", sharedKey);

    from("direct:encrypt")
        .log("Encrypting message")
        .marshal(sharedKeyCrypto)
        .log("Message encrypted: ${body}")
        .to("direct:decrypt");

    from("direct:decrypt")
        .log("Decrypting message")
        .unmarshal(sharedKeyCrypto)
        .log("Message decrypted: ${body}")
        .to("mock:decrypted");
}
项目:wildfly-camel    文件:CryptoDataFormatIntegrationTest.java   
@Test
public void testMarshalUnmarshallDes() throws Exception {

    final KeyGenerator generator = KeyGenerator.getInstance("DES");
    final CryptoDataFormat cryptoFormat = new CryptoDataFormat("DES", generator.generateKey());

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .marshal(cryptoFormat)
            .unmarshal(cryptoFormat);
        }
    });

    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        String result = producer.requestBody("direct:start", "password", String.class);
        Assert.assertEquals("password", result.trim());
    } finally {
        camelctx.stop();
    }
}
项目:camelinaction2    文件:MessageEncryptionTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            CryptoDataFormat crypto = new CryptoDataFormat("DES", secretKey);

            from("direct:start")
            .marshal(crypto)
            .to("mock:encrypted")
            .unmarshal(crypto)
            .to("mock:unencrypted");
        }
    };
}