123456789101112131415161718192021222324252627282930313233343536373839 |
- package com.iamberry.rst.utils;
- import com.auth0.jwt.internal.org.apache.commons.codec.binary.Base64;
- import com.auth0.jwt.internal.org.apache.commons.codec.binary.StringUtils;
- import net.sf.json.JSONObject;
- import org.apache.kafka.clients.consumer.ConsumerRecord;
- import java.io.File;
- import java.io.FileInputStream;
- import java.security.Key;
- import javax.crypto.Cipher;
- import javax.crypto.spec.SecretKeySpec;
- public class test {
- private static final String AES = "AES";
- public static String decrypt(String encryptedData, String secretKey) throws Exception {
- Key key = new SecretKeySpec(secretKey.getBytes(), AES);
- Cipher c = Cipher.getInstance(AES);
- c.init(2, key);
- byte[] decodedValue = Base64.decodeBase64(encryptedData);
- byte[] decValue = c.doFinal(decodedValue);
- String decryptedValue = StringUtils.newStringUtf8(decValue);
- return decryptedValue;
- }
- public static void main(String[] args) throws Exception {
- ConsumerRecord<String, String> record = new ConsumerRecord<String, String>("4", 1, 1, "data", "{\"data\":\"7uiBfrOFcdy/EDWxcT6SlZT7AORkrnWt533GP2oqstJT1zxbCQqLcNSyaITdfYZmhmZ8/vfzF9f8C5g7pKI8TvzaeeNu675pH3s5SP/5/bbL/U3eNahyWWQsMG1IhNtU66l6wd5Dwk5OTnoZmtRAliyN4Z9QwWjLU8DB11VW+EUGiD/1RodRhug3+ZLYgebFeJ/qT+1lbw86aX6QZNppgqByHL04wHsuQcOr6BVt1n0=\"}");
- String appKey = "5kkyurvvtt58bbuxueee";//填APP KEY
- String secretKey = "rhj6na6u3y6uhy6qrbb3944mg5uqqpbb";//APP SECRET
- String data = decrypt(JSONObject.fromObject(record.value()).getString("data"),
- secretKey.substring(8, 24));//解析后的真正数据
- System.out.println(data);
- }
- }
|