Search in sources :

Example 1 with AESUtils

use of com.alibaba.otter.node.etl.common.io.crypto.AESUtils in project otter by alibaba.

the class AESUtilsTest method test_simple.

@Test
public void test_simple() {
    AESUtils aes = new AESUtils();
    aes.generateSecretKey();
    byte[] data = getBlock(10 * 1024);
    byte[] encrypt = aes.encrypt(data);
    byte[] decrypt = aes.decrypt(encrypt);
    System.out.println("data length : " + data.length + " " + encrypt.length);
    check(data, decrypt);
}
Also used : AESUtils(com.alibaba.otter.node.etl.common.io.crypto.AESUtils) Test(org.testng.annotations.Test) BaseOtterTest(com.alibaba.otter.node.etl.BaseOtterTest)

Example 2 with AESUtils

use of com.alibaba.otter.node.etl.common.io.crypto.AESUtils in project otter by alibaba.

the class EncryptUtils method encrypt.

public static EncryptedData encrypt(byte[] input) {
    // 压缩数据
    byte[] compData = COMPRESSOR.compress(input);
    // 调用加密工具类
    AESUtils aes = new AESUtils();
    aes.generateSecretKey();
    // 加密数据
    byte[] encryptData = aes.encrypt(compData);
    return new EncryptedData(encryptData, aes.getSecretyKeyString(), ChecksumUtils.checksum(encryptData));
}
Also used : AESUtils(com.alibaba.otter.node.etl.common.io.crypto.AESUtils)

Example 3 with AESUtils

use of com.alibaba.otter.node.etl.common.io.crypto.AESUtils in project otter by alibaba.

the class EncryptUtils method decrypt.

public static byte[] decrypt(EncryptedData encode) {
    String destCrc = ChecksumUtils.checksum(encode.getData());
    //验证sign
    if (false == StringUtils.equals(encode.getCrc(), destCrc)) {
        throw new ChecksumException(String.format("orig: %s, parsed: %s not match", encode.getCrc(), destCrc));
    }
    // 调用加密工具类
    AESUtils aes = new AESUtils();
    aes.setSecretKeyString(encode.getKey());
    // 解密并解压数据
    return COMPRESSOR.decompress(aes.decrypt(encode.getData()));
}
Also used : AESUtils(com.alibaba.otter.node.etl.common.io.crypto.AESUtils) ChecksumException(com.alibaba.otter.node.etl.common.io.signature.ChecksumException)

Aggregations

AESUtils (com.alibaba.otter.node.etl.common.io.crypto.AESUtils)3 BaseOtterTest (com.alibaba.otter.node.etl.BaseOtterTest)1 ChecksumException (com.alibaba.otter.node.etl.common.io.signature.ChecksumException)1 Test (org.testng.annotations.Test)1