首页视频和首页介绍页

master
382696293@qq.com 2 years ago
parent b8d8d17dfd
commit 6f4b38b386

@ -0,0 +1,56 @@
package com.flossom.miniProgram.utils;
import java.nio.charset.Charset;
import java.util.Arrays;
public class PKCS7Encoder {
static Charset CHARSET = Charset.forName("utf-8");
static int BLOCK_SIZE = 32;
/**
* .
*
* @param count
* @return
*/
public 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);
}
/**
*
*
* @param decrypted
* @return
*/
public static byte[] decode(byte[] decrypted) {
int pad = 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;
}
}
Loading…
Cancel
Save