http 加解密 3des加解密

阅读更多

                                              3Des______加解密以及GZip______解压缩


        /* 声明加解密方式 */
private static final String ALGORITHM = "DESede";

/**
* 使用3des执行加密操作
*
* @param key
*            加密key
*
* @param src
*            未加密之前的数据
* @exception Exception
*
* @return byte[] 执行加密后的数据
*/
public static byte[] encrypt(byte[] key, byte[] src) {
            byte[] value = null;
            try {
               /* 生成密钥key */
               SecretKey deskey = new SecretKeySpec(key, ALGORITHM);
                 /* 执行加密操作 */

                    Cipher cipher = Cipher.getInstance(ALGORITHM);
                 cipher.init(Cipher.ENCRYPT_MODE, deskey);
                 value = cipher.doFinal(src);
           } catch (Exception e) {
                 e.printStackTrace();
           }
           return value;
}

/**
* 使用3des执行解密操作
*
* @param key
*            加密key
* @param src
*            加密之后的数据
* @exception Exception
*
* @return byte[] 执行解密后的数据
*/
public static byte[] decrypt(byte[] key, byte[] src) {
           byte[] value = null;
           try {
           /* 生成密钥key */
                SecretKey deskey = new SecretKeySpec(key, ALGORITHM);
           /* 执行解密 */
                Cipher cipher = Cipher.getInstance(ALGORITHM);
                cipher.init(Cipher.DECRYPT_MODE, deskey);
                value = cipher.doFinal(src);
           } catch (Exception e) {
                e.printStackTrace();
           }
           return value;
}

至于GZIP解压缩,附件中都已存在,此处就没必要赘述。。。。。。。

 

  • 3des_zip.rar (6.1 KB)
  • 下载次数: 0

你可能感兴趣的:(java,http,3des,加解密)