base64加密出现的问题
发表于|更新于
|浏览量:
背景
项目中仿QQ闪照功能, 图片的发送逻辑是, 先转base64, 然后加密, 最后加密后的字符串作为文件发送; 在处理接收的时候, 按照先下载文件, 然后读取文件内容, 再解密, 然后按照 base64 字符串的方式生成图片, 却一直失败.
解决方法
起初以为是, 加解密的问题, 仔细排查后, 排除了这个假设. 最后把解密后的字符串拷贝到VSCode中仔细观察发现, 其中多了很多\r\n.
搜索后发现, 是base64加密的问题, 由于base64一行不能超过76字符, 超过就会添加回车换行符(在 Windows中是\r\n, 在Linux中是\n). 而解析后其中的回车和换行就是错误信息, 所以解决方法是, 把\r\n替换为空字符串, 然后再去生成图片, 就正常了.
参考
文章作者: 今是昨非
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 今是昨非的博客!
相关推荐
2023-03-22
iOS推送播放语音播报更新
iOS推送播放语音播报更新接上篇如何让iOS推送播放语音,之前的结论是iOS如果需要送审商店只能播放本地的mp3文件,这里更新一下: 更新语音的播放,最终调用的方法是UNNotificationSound(named: xxx),而这个方法官方文档注释如下: 12// The sound file to be played for the notification. The sound must be in the Library/Sounds folder of the app's data container or the Library/Sounds folder of an app group data container. If the file is not found in a container, the system will look in the app's bundle. public convenience init(named name: UNNotificationSoundName) 注释里说,语音文件会从这三个地方...
2022-09-26
手把手教你创建widget2
手把手教你创建widget2接上篇iOS Widget,这里介绍下WidgetBundle的用法和怎么做一个支付宝类似的 widget,上篇里把WidgetBundle写成了WidgetGroup,我的错。 WidgetBundle 的用法再来回顾一下什么情况下使用 WidgetBundle,上篇里介绍了supportedFamilies,可以设置Widget 不同的尺寸,比如Small、Meidum、Large等,但是如果想要多个同尺寸的 Widget ,比如:想要两个Small尺寸的 Widget ,类似于下面东方财富 Widget 的效果,就需要用WidgetBundle,设置多个Widget。 WidgetBundle的使用不难,下面来看下,上篇最后的代码(可以去https://github.com/mokong/WidgetAllInOne下载,打开 Tutorial2),只显示了一个 Medium 尺寸的 Widget,这里修改为使用WidgetBundle显示两个Medium尺寸的 Widget。 新建SwiftUIView,...
2022-04-21
Algorithem_Merge Two Binary Trees
Algorithem_Merge Two Binary TreesYou are given two binary trees root1 and root2. Imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not. You need to merge the two trees into a new binary tree. The merge rule is that if two nodes overlap, then sum node values up as the new value of the merged node. Otherwise, the NOT null node will be used as the node of the new tree. Return the merged tree. Note: The merging process must...
2024-08-17
FirebaseFunctionError 处理
背景做一个 Firebase 相关的项目,其中创建用户的时候,用的是Cloud Functions,调用的时候一直报错,错误信息只有”INTERNAL”。 Deploying Function Error on Cloud Function with error code 13 and Message “INTERNAL” 排查步骤网上搜索之后,有说字段不对应的,有说调用方式不对的,但是尝试后把这两个原因都排除了。 然后去 Firebase 的 Console 中查看,找到 Function,再找到调用的函数名字,点击右侧的竖三角,查看详细信息,发现里面错误信息为空。不要急,点击顶部 Tab,切换到 日志 下,然后从日志中查看报错信息,就能看到调用这个函数哪里报错了。具体步骤的截图如下:
2021-08-04
iOS 虚拟定位原理与预防
iOS 虚拟定位原理与预防背景说到虚拟定位,常有印象都是安卓上的分身软件甚至系统自带的位置穿越(笔者曾经使用过ZUK Z2系统自带的位置穿越),会认为iOS上虚拟定位比较困难。笔者没调研之前也是这么认为,之前已知的虚拟定位是使用Xcode添加GPX文件,编辑经纬度,从而实现虚拟定位。但是这种操作也只有熟悉iOS开发的人才能操作,而且需要mac电脑,故而笔者印象中也是iOS上虚拟定位比较困难。 然而经过调研之后,笔者发现,iOS的虚拟定位没有那么困难,甚至相比于安卓更简单。下面就来介绍一下iOS中几种虚拟定位的方法。 虚拟定位的几种办法及原理笔者调研后,发现iOS上面虚拟定位大致可有4中情况: 使用Xcode通过GPX文件虚拟定位 使用爱思助手中的虚拟定位功能直接虚拟定位 通过外接设备,比如蓝牙和手机连接,发送虚拟定位数据来虚拟定位 越狱设备中通过hook定位方法,来虚拟定位 下面就来一个个分析实践: 使用Xcode通过GPX文件虚拟定位使用Xcode通过GPX文件虚拟定位,iOS开发一般比较熟悉,操作步骤是: 新创建一个iOS项目,然后添加文件,选择创建GPX文件 编辑...
2022-04-21
Algorithem_Populating Next Right Pointers in Each Node
Algorithem_Populating Next Right Pointers in Each NodeYou are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following definition: 123456struct Node { int val; Node *left; Node *right; Node *next;} Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL. Initially, all next pointers are set to NULL. Example 1: 12Input: root...