解密方法无法将接收到的字节数组转换为字符串。
    public String decryptData(String data, SecretKeySpec key) throws Exception{
    Cipher cipher = Cipher.getInstance("AES");
    cipher.init(Cipher.DECRYPT_MODE, key);
    byte[] decodedValue = Base64.decode(data, Base64.DEFAULT);
    byte[] decValue = cipher.doFinal(decodedValue);
    String outputData = new String(decValue, StandardCharsets.US_ASCII);
    Log.d("Log byte:", decodedValue.toString());
    Log.d("Log byte:", decValue.toString());
    Log.d("Log str:", outputData);
}输出日志:
D/Log byte:: [B@4b0fd32
D/Log byte:: [B@32d3a83
D/Log str:: cipher.doFinal()返回一个空数组,我想这就是我得到空字符串值的原因
发布于 2022-04-26 07:44:12
我用这个方法用AES方法解密。
 private final String characterEncoding = "UTF-8";
private final String cipherTransformation = "AES/CBC/PKCS5Padding";
private final String aesEncryptionAlgorithm = "AES";
public String decrypt(String encryptedText, String key) throws KeyException, GeneralSecurityException, GeneralSecurityException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException, IOException {
        byte [] cipheredBytes = Base64.decode(encryptedText, Base64.DEFAULT);
        byte[] keyBytes = getKeyBytes(key);
        return new String (decrypt(cipheredBytes, keyBytes, keyBytes), characterEncoding);
    }https://stackoverflow.com/questions/72008486
复制相似问题