收藏
回答

解密用户信息偶尔会出现乱码,怎么解决?

String data = "6n8O4a/8pKUBkg6f1MhKAnL83hbpdCrLGa7yeVo0J2QtDxshWFVdtXz/kDMX8rUHWTHXSEV4N3pQeifqWYRk+/WLLTf1/y1O4gGnOoTvwnU8jNN4GEMokBR+qtf75btaDq89wQy5IFdXhvivyaIO9EwFFm+ncutg5Y/BimKxAo4+leJHjiUNyXmZCVzz2wluNXogBuYNEoIOY6p/y5dE0naKS/3/5KyA1TZt8p9B8XPRXEFVucWNc7c80ou2WXCXCn1P8s+O3w59/hw9EtxUwuDwp3CObKlrPD4GT44rl9l64hk4Q2AST/8IspvRCFgtWew2l6hZeGMYTmziBH2mozbUrSizACi45T2sZk3RyWxPteZIAH2HzubsIlxbZ/XiGKRKINus7V3u4yuJlON7IYKLISpWzOTUkWGnKd15o3oO8d0fI2gsoeuXK1pNWdqS2Vfs0R5teSlFbsqcztVfRkzEymwEb+8wEOpZ/pkxWlWpbfb5vdo2QFaPC5fNU7pONA65JyKihfFqThhIeqAt1A==";
String sessionKey = "1jD\\/wapVuP0zcy0uNJm5Dg==";
String iv = "nztsHOp34sQwgXtX07x5cw=="

解密方法

public static String decrypt(String sessionKey, String encryptedData, String ivStr) {
    try {
        AlgorithmParameters params = AlgorithmParameters.getInstance("AES");
        params.init(new IvParameterSpec(org.apache.commons.codec.binary.Base64.decodeBase64(ivStr)));
        Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
        cipher.init(2, new SecretKeySpec(org.apache.commons.codec.binary.Base64.decodeBase64(sessionKey), "AES"), params);
        return new String(Pkcs7Encoder.decode(cipher.doFinal(org.apache.commons.codec.binary.Base64.decodeBase64(encryptedData))), StandardCharsets.UTF_8);
    } catch (Exception var5) {
        throw new BadException("AES解密失败");
    }
}
最后一次编辑于  03-09
回答关注问题邀请回答
收藏

2 个回答

  • 浮动
    浮动
    03-09

    03-09
    赞同 2
    回复 1
    • 李新
      李新
      03-19
      现在有解决吗
      03-19
      回复
  • 李新
    李新
    03-19

    这种怎么解决呢

    03-19
    赞同
    回复
登录 后发表内容
问题标签