zoukankan      html  css  js  c++  java
  • java.security.Key 在main方法中与在tomcat中得到的encode不同,why?

    public class DESUtils {
    
        private static Key key;
        private static String KEY_STR = "eloan_yzld";
    
        static {
            try {
                KeyGenerator generator = KeyGenerator.getInstance("DES");
                SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
                secureRandom.setSeed(KEY_STR.getBytes());
                generator.init(secureRandom);
    
                key = generator.generateKey();
                byte[] b = key.getEncoded();
                System.out.print("key==============");
                for(int i=0; i<b.length; i++) {
                    System.out.print(b[i] + " ");
                    // 本地main 方法跑得到[-80, -60, 19, -33, 112, -75, -12, 93]
                    // 从tomcat中启动时得到[-26, -92, -62, 25, 55, -125, 14, -42]
                }
                System.out.println();
                generator = null;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    ...
    }

    实在想不明白为什么会这样

    19:40:24

    刚刚把项目打了个war包,扔到linux服务器下跑,结果发现,日志中打出了

    这说明在linux下是正常的

    20:05:47

    实在看不出问题了,一狠心换了个工作空间,完美运行~!

    
    
  • 相关阅读:
    如何在自定义端口上运行 Spring Boot 应用程序?
    FileUpload拦截器
    UI标签
    OGNL
    你对测试最大的兴趣在哪里?为什么?
    举例说明同步和异步。
    git 克隆分支
    JQuery 选择器
    JQuery对象和Dom对象
    简单的JQuery之Ready
  • 原文地址:https://www.cnblogs.com/goldeneast/p/5939884.html
Copyright © 2011-2022 走看看