三重 DES 加密字符串生成“\n”

在加密字符串时,它会'\n'在字符串的末尾生成。


这就是我进行加密的方式


public static String encrypt(String plainText) throws Exception {

        byte[] tdesKeyData = Consts.getSecretKey().getBytes();

        byte[] myIV = Consts.getInitializationVector().getBytes();

        SecretKeySpec myKey = new SecretKeySpec(tdesKeyData, "DES");

        IvParameterSpec ivspec = new IvParameterSpec(myIV);

        Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS7Padding");

        cipher.init(Cipher.ENCRYPT_MODE, myKey, ivspec);


        byte[] plainTextBytes = plainText.getBytes("UTF-8");

        byte[] buf = cipher.doFinal(plainTextBytes);

        byte[] base64Bytes = Base64.encode(buf, Base64.DEFAULT);

        String base64EncryptedString = new String(base64Bytes);

        return base64EncryptedString;

    }

请有人指导我,我在这里做错了什么?提前致谢。


慕妹3146593
浏览 92回答 1
1回答

浮云间

Base64.NO_WRAP编码器标志位省略所有行终止符(即,输出将在一根长线上)。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java