AES/CBC/NoPadding加密后数据使用PKCS7Padding补码方式解密后出现数据被截断的问题
-
java不支持 PKCS7Padding补码方式
public static String encrypt(String Data, String password){ try { byte[] iv = DEFAULT_IV.getBytes(DEFAULT_CHARSET); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding"); int blockSize = cipher.getBlockSize(); byte[] dataBytes = Data.getBytes(DEFAULT_CHARSET); int plaintextLength = dataBytes.length; if (plaintextLength % blockSize != 0) { plaintextLength = plaintextLength + (blockSize - (plaintextLength % blockSize)); } byte[] plaintext = new byte[plaintextLength]; System.arraycopy(dataBytes, 0, plaintext, 0, dataBytes.length); IvParameterSpec ivspec = new IvParameterSpec(iv); cipher