导出 base64 加密的 jpg

export a base64-encrypted jpg

我想导出 base64 加密的 jpg。

这是我的方法:

1) table 中的 Select 单元格使用 Base64 代码

2) 用"base64_decode"

解密代码

3) 将文件保存为 .jpg 文件

解密时出现如下错误信息

Error in rawToChar(base64_decode(testbody)) : 
  embedded nul in string: 

这就是我的代码的样子:

testbody = Boden$body[5]
test = rawToChar(base64_decode(testbody))

这是testbody的内容:

/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCAA2AHcDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD9QdS1K306NWnk2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rIzt6tsd1/4G1d/gUYFAcsTmLPwda2FnBbWxW2t4I0ijiij2IiKNqqq/w1Y/4RJP+fl/++a6GikaGHZ+HzZvu+0u6N95NtWf7IX/AJ6t/wB81p0UAZn9kf8ATX/xypU07Z/y0q9RQAxE20U+igCOXqn+8KxLnxZp9pdTQSyz+ZA22XZbSuq9P4lTH8S1szdU/wB6vIPHvgRfGF5qMU9xrGmjF1DG9jbu6SrPFBnft+8v7r7tAHpaeJ7KZdyx3rr/AHl0+f8A+IqF/F+mrKsb/axM/wB2JrGfd/3zsrxNPhBdwwmD+39Ymhld3neXT7rzd3z+U8TrL8mzd/wLYtRTfCDVE1C91WHXtUOtXibLi5i0q4R22vuTYzS/L/d/i+VmoA96/wCEntP+eV//AOC64/8AiKZ/wlVl/wA87/8A8F9x/wDEV8+6R8HtZu7RX1fxJrlmzRuG0+xgunt4PndlRX37mVNysu+vcrHxJNDGq3NtfzhV2l10+VWdqAND/hKrL/nnf/8AgvuP/iKP+Eqsv+ed/wD+C+4/+Ipv/CVR/wDQM1T/AMA2o/4SqP8A6Bmqf+AbUAJL4s0+3heWVL2GJF3sz6fOu1f++K3OorxIeDLiy1PWL46r4p1SwaG5OkaJcQP5VnLOreb833pfvfJ5v+qV2Vf9n2qIbI0WgCSiiigAooooAKKKKAI5eqf7wqSiigAooooAKKKKACiiigAooooAKKKKACiiigAooooA/9k=

如果你只是想把图片保存在某个地方,你可以这样做

raw <- base64enc::base64decode(testbody)
writeBin(raw, "foo.jpg")

首先,将 base64 数据转换为字节,然后将这些字节写入文件。如果您想先使用 R 中的数据,您也可以将它们读取为 JPEG 图像

pic <- jpeg::readJPEG(raw)
plot(1:2, type="n")
rasterImage(pic, 1, 1, 2, 2)
jpeg::writeJPEG(pic, "pic.jpg")