Git Product home page Git Product logo

Comments (4)

looly avatar looly commented on June 22, 2024

image

做了一些兼容。

from hutool.

reixuemin avatar reixuemin commented on June 22, 2024

这是我用最新的版本跑出来的结果,它没有走你截图的else部分

from hutool.

changhr2013 avatar changhr2013 commented on June 22, 2024

mark 一下,有空展开讲讲原理 😂,最近求知的同学好多。

如果你仅仅是想知道答案的话,你可以认为你添加的字母 s(指代 6 个比特) 因为不满足 Base64 要求的最小置换单元长度(8 个比特),被 hutool 库丢弃了,至于是丢弃还是报错,这其实跟库的解码行为有关,看库是倾向于尽量解码出更多的内容,还是库要对内容做严格的合法性校验。

from hutool.

looly avatar looly commented on June 22, 2024

@changhr2013 @reixuemin 解码逻辑大概是解析固定位数,的整数倍,然后多余的字符忽略掉了。

Hutool的解码相对宽松,最终目标是“尽可能”解析出Base64内容。

举个例子,加入给定内容中有Base64和非Base64混合内容,通过宽松方式解码,就会尽可能的找出被解码的内容。

final String str ="我是不需要解码的内容5Lym5a625piv5LiA5Liq6Z2e5bi46ZW/55qE5a2X56ym5LiyNjY我是不需要解码的内容";
// 伦家是一个非常长的字符串66
Base64.decodeStr(str);

你会发现前面和后面的内容都会被丢弃,重要的逻辑在这里:

image

如果你需要严格的解码,考虑使用java.util.Base64.getDecoder().decode(in)

from hutool.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.