相当于Java中的MySQL压缩函数

时间:2016-08-22 15:53:19

标签: java mysql compression base64 zlib

想在mysql中压缩文本,默认使用zlib压缩算法,然后将其编码为base64字符串,然后在java中匹配这些结果,以便在java中我可以解压缩文本。任何人都可以帮我解决这些建议吗?

// Here is the sample java code:
String inputString ="have a good day"; 

   final Cipher encryptCipher = Cipher.getInstance("AES");                          
            encryptCipher.init(Cipher.ENCRYPT_MODE,   generateMySQLAESKey("default", "UTF-8"));     


            String encryptedText =new String(Hex.encodeHex(encryptCipher.doFinal(inputString.getBytes("UTF-8"))));

    Deflater deflater = new Deflater();
    deflater.setInput(encryptedText );
    ByteArrayOutputStream outputStream = new             ByteArrayOutputStream(data.length);  
    deflater.finish();
    byte[] buffer = new byte[1024];
    while (!deflater.finished()) {
        int count = deflater.deflate(buffer); // returns the generated
                                                // code... index
        outputStream.write(buffer, 0, count);
    }
    outputStream.close();
    byte[] output = outputStream.toByteArray();

    return Base64.encodeBase64String(output);


 //I want it to match mysql query like:

select TO_BASE64(COMPRESS(HEX(AES_ENCRYPT("have a good day",default))) from dual;

0 个答案:

没有答案