我需要使用 base64 的 RFC2045-MIME 变体转换编码字符串。但是我找不到任何选项来快速执行此操作。目前我使用这种方法:
var str = "\(test1):\(test2)"
str = str.data(using: .utf8)!.base64EncodedString(options: Data.Base64EncodingOptions(rawValue: UInt(0)))
但这只是标准的 base64 编码,而不是 RFC2045-MIME 变体。我如何使用 RFC2045-MIME 变体?
最佳答案
RFC 2045 和 RFC 4686 中指定的 base64 编码之间的唯一区别是 RFC 2045 指定最大行长度为 76 个字符,行由 CRNL 分隔。
base64EncodedString(options:)
的文档说默认行结尾是 CRNL,所以:
let data = str.data(using: .utf8)!
let b64 = data.base64EncodedString(options: .lineLength76Characters)
关于ios - swift 中 Base 64 的 RFC2045-MIME 变体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49493760/