Swiftpack.co -  swift-extras/swift-extras-base64 as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Base64 encode and decode without the use of Foundation in pure Swift.
.package(url: "https://github.com/swift-extras/swift-extras-base64.git", from: "v0.6.0")


Swift 5.1 github-actions codecov macOS tuxOS

This package provides a base64 encoder and decoder in Swift without the use of Foundation. The implementation is RFC4648 complient and is faster than the Foundation base64 implementation.

To achieve performance the implementation uses Chromium precomputed lookup tables and makes heavy use of unsafe swift API. When Swift has better support for SIMD instructions this might be an area worth exploring.


  • ☑ support for base64 and base64url
  • ☑ faster than Foundation
  • ☑ padding can be omitted
  • ☐ decoding can ignore line breaks
  • ☐ encoding can insert line breaks

A former implementation of this package is used in swift-nio's websocket implementation.


Super simple performance test to ensure speediness of this implementation. Encoding and decoding 1m times the base64 string:


Tests were run on a MacBook Pro (16-inch, late 2019). Processor: 2.4 GHz 8-Core Intel Core i9.

macOS - swift 5.3

Encoding Decoding
Foundation 2.08s 2.15s
swift-extras-base64 0.66s 0.54s
Speedup 3x 4x

Linux - swift 5.3

Encoding Decoding
Foundation 1.01s 5.5s
swift-extras-base64 0.27s 0.41s
Speedup 3x ~10x

Literature for a faster algorithm

I would really like to speed up this project further to be way faster than it is today. Some food for thought of how this could be tackled can be found here:


As of today (2019-12-10), the author is aware of only one alternative that offers merely encoding.


Stars: 58
Last commit: 7 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

swift-extras-base64 0.7.0
7 weeks ago
  • Added support for Base32 encoding and decoding (thanks @adam-fowler!) (#29)

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API