From 81da61b828e29b7745e1382dfbbaeb685dc083ef Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 23 一月 2024 17:17:55 +0800 Subject: [PATCH] 抖音转链修改 --- utils/src/main/java/com/qq/weixin/mp/aes/PKCS7Encoder.java | 134 ++++++++++++++++++++++---------------------- 1 files changed, 67 insertions(+), 67 deletions(-) diff --git a/utils/src/main/java/com/qq/weixin/mp/aes/PKCS7Encoder.java b/utils/src/main/java/com/qq/weixin/mp/aes/PKCS7Encoder.java index b402ab0..9c3879d 100644 --- a/utils/src/main/java/com/qq/weixin/mp/aes/PKCS7Encoder.java +++ b/utils/src/main/java/com/qq/weixin/mp/aes/PKCS7Encoder.java @@ -1,67 +1,67 @@ -/** - * 瀵瑰叕浼楀钩鍙板彂閫佺粰鍏紬璐﹀彿鐨勬秷鎭姞瑙e瘑绀轰緥浠g爜. - * - * @copyright Copyright (c) 1998-2014 Tencent Inc. - */ - -// ------------------------------------------------------------------------ - -package com.qq.weixin.mp.aes; - -import java.nio.charset.Charset; -import java.util.Arrays; - -/** - * 鎻愪緵鍩轰簬PKCS7绠楁硶鐨勫姞瑙e瘑鎺ュ彛. - */ -class PKCS7Encoder { - static Charset CHARSET = Charset.forName("utf-8"); - static int BLOCK_SIZE = 32; - - /** - * 鑾峰緱瀵规槑鏂囪繘琛岃ˉ浣嶅~鍏呯殑瀛楄妭. - * - * @param count 闇�瑕佽繘琛屽~鍏呰ˉ浣嶆搷浣滅殑鏄庢枃瀛楄妭涓暟 - * @return 琛ラ綈鐢ㄧ殑瀛楄妭鏁扮粍 - */ - static byte[] encode(int count) { - // 璁$畻闇�瑕佸~鍏呯殑浣嶆暟 - int amountToPad = BLOCK_SIZE - (count % BLOCK_SIZE); - if (amountToPad == 0) { - amountToPad = BLOCK_SIZE; - } - // 鑾峰緱琛ヤ綅鎵�鐢ㄧ殑瀛楃 - char padChr = chr(amountToPad); - String tmp = new String(); - for (int index = 0; index < amountToPad; index++) { - tmp += padChr; - } - return tmp.getBytes(CHARSET); - } - - /** - * 鍒犻櫎瑙e瘑鍚庢槑鏂囩殑琛ヤ綅瀛楃 - * - * @param decrypted 瑙e瘑鍚庣殑鏄庢枃 - * @return 鍒犻櫎琛ヤ綅瀛楃鍚庣殑鏄庢枃 - */ - static byte[] decode(byte[] decrypted) { - int pad = (int) decrypted[decrypted.length - 1]; - if (pad < 1 || pad > 32) { - pad = 0; - } - return Arrays.copyOfRange(decrypted, 0, decrypted.length - pad); - } - - /** - * 灏嗘暟瀛楄浆鍖栨垚ASCII鐮佸搴旂殑瀛楃锛岀敤浜庡鏄庢枃杩涜琛ョ爜 - * - * @param a 闇�瑕佽浆鍖栫殑鏁板瓧 - * @return 杞寲寰楀埌鐨勫瓧绗� - */ - static char chr(int a) { - byte target = (byte) (a & 0xFF); - return (char) target; - } - -} +/** + * 瀵瑰叕浼楀钩鍙板彂閫佺粰鍏紬璐﹀彿鐨勬秷鎭姞瑙e瘑绀轰緥浠g爜. + * + * @copyright Copyright (c) 1998-2014 Tencent Inc. + */ + +// ------------------------------------------------------------------------ + +package com.qq.weixin.mp.aes; + +import java.nio.charset.Charset; +import java.util.Arrays; + +/** + * 鎻愪緵鍩轰簬PKCS7绠楁硶鐨勫姞瑙e瘑鎺ュ彛. + */ +class PKCS7Encoder { + static Charset CHARSET = Charset.forName("utf-8"); + static int BLOCK_SIZE = 32; + + /** + * 鑾峰緱瀵规槑鏂囪繘琛岃ˉ浣嶅~鍏呯殑瀛楄妭. + * + * @param count 闇�瑕佽繘琛屽~鍏呰ˉ浣嶆搷浣滅殑鏄庢枃瀛楄妭涓暟 + * @return 琛ラ綈鐢ㄧ殑瀛楄妭鏁扮粍 + */ + static byte[] encode(int count) { + // 璁$畻闇�瑕佸~鍏呯殑浣嶆暟 + int amountToPad = BLOCK_SIZE - (count % BLOCK_SIZE); + if (amountToPad == 0) { + amountToPad = BLOCK_SIZE; + } + // 鑾峰緱琛ヤ綅鎵�鐢ㄧ殑瀛楃 + char padChr = chr(amountToPad); + String tmp = new String(); + for (int index = 0; index < amountToPad; index++) { + tmp += padChr; + } + return tmp.getBytes(CHARSET); + } + + /** + * 鍒犻櫎瑙e瘑鍚庢槑鏂囩殑琛ヤ綅瀛楃 + * + * @param decrypted 瑙e瘑鍚庣殑鏄庢枃 + * @return 鍒犻櫎琛ヤ綅瀛楃鍚庣殑鏄庢枃 + */ + static byte[] decode(byte[] decrypted) { + int pad = (int) decrypted[decrypted.length - 1]; + if (pad < 1 || pad > 32) { + pad = 0; + } + return Arrays.copyOfRange(decrypted, 0, decrypted.length - pad); + } + + /** + * 灏嗘暟瀛楄浆鍖栨垚ASCII鐮佸搴旂殑瀛楃锛岀敤浜庡鏄庢枃杩涜琛ョ爜 + * + * @param a 闇�瑕佽浆鍖栫殑鏁板瓧 + * @return 杞寲寰楀埌鐨勫瓧绗� + */ + static char chr(int a) { + byte target = (byte) (a & 0xFF); + return (char) target; + } + +} -- Gitblit v1.8.0