private static final Cipher DES_CIPHER;

static {
    try {
        DES_CIPHER = Cipher.getInstance("DES/ECB/PKCS1Padding");
    } 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(IcbcConstant.ENCODING_GBK), "DES"));
        byte[] encryptedData = DES_CIPHER.doFinal(encryptString.getBytes(IcbcConstant.ENCODING_GBK));
        return new String(encryptedData, IcbcConstant.ENCODING_GBK);
    } 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(IcbcConstant.ENCODING_GBK), "DES"));
        byte decryptedData[] = DES_CIPHER.doFinal(decryptString.getBytes(IcbcConstant.ENCODING_GBK));
        return new String(decryptedData, IcbcConstant.ENCODING_GBK);
    } catch (Throwable e) {
        throw Throwables.propagate(e);
    }
}

  

相关文章:

  • 2021-12-11
  • 2022-01-17
  • 2021-11-27
  • 2022-02-18
  • 2022-12-23
  • 2022-12-23
  • 2022-01-30
  • 2021-12-27
猜你喜欢
  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
  • 2022-01-25
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案