zoukankan      html  css  js  c++  java
  • DES加密

    import java.util.Base64;
    import javax.crypto.Cipher;
    import javax.crypto.SecretKey;
    import javax.crypto.SecretKeyFactory;
    import javax.crypto.spec.DESKeySpec;
    import javax.crypto.spec.IvParameterSpec;
    String key ="*******";//引用key
    String body=vars.get("codebody");
    //vars.get("codebody");//引用参数
    //print("?????????........"+CartID);
    // 加密方法
    public String EncryptAsDoNet(String message) {
        try {
            Base64.Encoder encoder = Base64.getEncoder();
            Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
            DESKeySpec desKeySpec = new DESKeySpec(key.getBytes("UTF-8"));
            SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
            SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
            IvParameterSpec iv = new IvParameterSpec(key.getBytes("UTF-8"));
            cipher.init(Cipher.ENCRYPT_MODE, secretKey, iv);
            byte[] encryptbyte = cipher.doFinal(message.getBytes());
            String str =encoder.encodeToString(encryptbyte);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

            return str.replace(" ", "");
        }catch (Throwable e) {
            e.printStackTrace();
            return "";
        }
    }    
        
     // 加密
    String DESSign = EncryptAsDoNet(body);
    //print(enString);
    //${__setProperty("NewenString",${enString},)};
    vars.put("DESSign",DESSign);
    log.info("请求登陆验证码参数"+body);


    //print(props.get("NewenString"));

    竹杖芒鞋轻胜马,一蓑烟雨任平生。 回首向来萧瑟处,也无风雨也无晴。
  • 相关阅读:
    00077_集合
    python、js、php区别---6、函数相关
    python、js、php区别---5、存储结构
    python、js、php区别---4、基本结构
    python、js、php区别---3、运算符
    python、js、php区别---2、数据类型
    python、js、php区别---1、基本区别
    python疑难问题---3、可变和不可变数据类型
    python疑难问题---2、字典排序
    python疑难问题---1、遍历列表的三种方式
  • 原文地址:https://www.cnblogs.com/yaobiluo/p/12186205.html
Copyright © 2011-2022 走看看