首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >配置SSL密码,如在tomcat server.xml中配置${server.xml}

配置SSL密码,如在tomcat server.xml中配置${server.xml}
EN

Stack Overflow用户
提问于 2015-06-02 14:21:03
回答 1查看 1.8K关注 0票数 1

我想在Tomcat server.xml中配置SSL密码,比如server.xml。对于Tomcat 7,我已经编写了这样做的代码,它运行良好。但是在Tomcat 8中,它没有被唤醒,因为IntrospectionUtils正在从tomcat-coyote.jar移动。

如果有人在Tomcat 8做过同样的事情,请告诉我如何进行。

下面是在Tomcat 7中工作的代码示例。要运行,请从下面的代码创建一个jar,在catalina.proerties中只添加两行:

org.apache.tomcat.util.digester.PROPERTY_SOURCE=com.sumit.logic.Decrypt keystore.password=9Gm4M64FG+JJhNBtk+bUWg==

代码:

代码语言:javascript
复制
package com.comviva.logic;

import java.io.IOException;
import javax.crypto.Cipher;
import org.apache.tomcat.util.IntrospectionUtils;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.comviva.util.Util;

    public class Decrypt implements IntrospectionUtils.PropertySource {

        static Log log = LogFactory.getLog(Decrypt.class);
        static int count =0;
        static String encrypted_password=null;
        private static byte[] key = {
            0x74, 0x68, 0x69, 0x73, 0x49, 0x73, 0x41, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x4b, 0x65, 0x79
        };//"thisIsASecretKey";


        public static String decrypt(String strToDecrypt)
        {
            try
            {
                Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING");
                final SecretKeySpec secretKey = new SecretKeySpec(key, "AES");
                cipher.init(Cipher.DECRYPT_MODE, secretKey);
                final String decryptedString = new String(cipher.doFinal(Base64.decodeBase64(strToDecrypt)));
                return decryptedString;
            }
            catch (Exception e)
            {
                log.error("Error while decrypting", e);
                return null;
            }

        }

        @Override
        public String getProperty(String arg0) {

            System.out.println("Count is " + count++);

            String fname=this.getClass().getClassLoader().getResource("").getFile();
            fname=fname.substring(0, fname.length()-4);
            String OS = System.getProperty("os.name").toLowerCase();
            if(OS.indexOf("win")>=0)
            {
                log.info("System Type is :"+OS);
                fname=fname.concat("conf\\catalina.properties\n");
                System.out.print("File Name is :"+fname);
            }
            else
            {
                log.info("System Type is :"+OS);
                fname=fname.concat("conf/catalina.properties\n");
                System.out.print("File Name is :"+fname);
            }
            log.info("File is read successfully");
            try {
                Util utility=new Util(fname);
                log.info("Hello");

                encrypted_password=utility.getValue(arg0);
                log.info("ecrypted password is :" + encrypted_password);
                System.out.println("ecrypted password is :" + encrypted_password);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            return decrypt(encrypted_password);
        }

    }
EN

回答 1

Stack Overflow用户

发布于 2016-01-25 12:50:23

通过在CATALINA_OPTS中传递下面的参数,我能够在Tomcat 8中完成它

代码语言:javascript
复制
-Dorg.apache.tomcat.util.digester.PROPERTY_SOURCE=com.sumit.logic.Decrypt 

IntrospectionUtils被移到"tomcat-util.jar“中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30598753

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档