use of com.alibaba.otter.node.etl.common.io.signature.ChecksumException in project otter by alibaba.
the class AbstractHttpPipe method decodeFile.
protected void decodeFile(File file, String key, String crc) {
// 读取校验信息
RandomAccessFile raf = null;
try {
raf = new RandomAccessFile(file, "rw");
long totallength = file.length();
int keyLength = ByteUtils.stringToBytes(key).length;
int crcLength = ByteUtils.stringToBytes(crc).length;
// 长度字段起始位
long pos = totallength - keyLength - crcLength;
// 游标
raf.seek(pos);
// 读取key内容
byte[] keyBytes = new byte[keyLength];
raf.read(keyBytes, 0, keyLength);
String keystr = ByteUtils.bytesToString(keyBytes);
if (!key.equals(keystr)) {
throw new ChecksumException("unmatch garble key with[" + key + "],[" + keystr + "]");
}
// 读取校验码长度
raf.seek(pos + keyLength);
byte[] crcBytes = new byte[crcLength];
raf.read(crcBytes, 0, crcLength);
String crcStr = ByteUtils.bytesToString(crcBytes);
if (!crc.equals(crcStr)) {
throw new ChecksumException("unmatch crc with[" + crc + "],[" + crcStr + "]");
}
// 设置文件长度
raf.setLength(pos);
} catch (Exception e) {
throw new PipeException("read_encrypted_error", e);
} finally {
IOUtils.closeQuietly(raf);
}
}
use of com.alibaba.otter.node.etl.common.io.signature.ChecksumException 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()));
}
Aggregations