德code的base64数据连接在bash codeD [英] Decode base64 data encoded in bash

查看:159
本文介绍了德code的base64数据连接在bash codeD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图去code的一些数据,我带在bash codeD使用

I'm trying to decode some data which I encoded in bash using

base64 -in file.txt -out encodedFile.txt

解读它在bash是没有问题的。

Decoding it in bash is no problem.

但是,当我尝试使用脱code将其在Objective-C

But when I try to decode it in Objective-C using

//fetch encoded data from file system, put it in
//NSData *encoded
NSData *decoded = [[NSData alloc] initWithBase64EncodedData:encoded withOptions:0];

我总是收到零。

修改

我试过编码Objective-C的同一个文件,发现只有一个小的差异:

I tried encoding the same file in Objective-C and noticed there is only one small difference:

恩$ C $在bash CD:

Encoded in bash:

dGhpcyBpcyBhIHRlc3Qh

恩codeD在Objective-C

Encoded in Objective-C:

VGhpcyBpcyBhIHRlc3Qh

只有第一个字符是不同的。

Only the first character is different.

推荐答案

我想它了。

显然有一个换行符( \\ n )追加到文件的末尾。
一旦我删除,它的工作正常。

Apparently there was a newline (\n) appended to the end of the file. Once I removed that, it worked normally.

对于那些谁感兴趣的话,我设法用做这一个命令

For those who are interested, I managed to do this in one command using

base64 -i file.txt | tr -d '\n' > encodedFile.txt

这篇关于德code的base64数据连接在bash codeD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆