zoukankan      html  css  js  c++  java
  • Java DESede 加解密("DESede/ECB/PKCS5Padding")

    private static final Cipher DES_CIPHER;
    
    
    static {
        try {
            DES_CIPHER = Cipher.getInstance("DESede/ECB/PKCS5Padding");
        } catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
            throw Throwables.propagate(e);
        }
    }
    
    public static String encryptDES(String encryptString, String encryptKey) {
        try {
            DES_CIPHER.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(encryptKey.getBytes(IcbcBindConstant.ENCODING_GBK), "DESede"));
            byte[] encryptedData = DES_CIPHER.doFinal(encryptString.getBytes(IcbcBindConstant.ENCODING_GBK));
            String hexData = Hex.encodeHexString(encryptedData).toUpperCase();
            return StringUtils.leftPad(String.valueOf(hexData.length()), 6, '0') + hexData;
        } catch (Throwable e) {
            throw Throwables.propagate(e);
        }
    }
    
    public static String decryptDES(String decryptString, String decryptKey) {
        try {
            DES_CIPHER.init(Cipher.DECRYPT_MODE, new SecretKeySpec(decryptKey.getBytes(IcbcBindConstant.ENCODING_GBK), "DESede"));
            byte[] decryptedData = DES_CIPHER.doFinal(Hex.decodeHex(decryptString.substring(6).toCharArray()));
            return new String(decryptedData, IcbcBindConstant.ENCODING_GBK);
        } catch (Throwable e) {
            throw Throwables.propagate(e);
        }
    }
  • 相关阅读:
    团队冲刺八
    第十一周学习进度
    团队冲刺七
    团队冲刺六
    团队冲刺五
    冲刺第五天
    冲刺第四天
    冲刺第三天
    冲刺第二天
    冲刺第一天
  • 原文地址:https://www.cnblogs.com/frankyou/p/8398729.html
Copyright © 2011-2022 走看看