explaingit

krzyzanowskim/cryptoswift

10,548SwiftAudience · developerComplexity · 2/5Setup · easy

TLDR

A pure-Swift cryptography library for iOS, macOS, Linux, and Android that provides hashing, encryption, password hashing, and message authentication with no system library dependencies.

Mindmap

mindmap
  root((CryptoSwift))
    Hashing
      MD5 SHA-1
      SHA-2 SHA-3
    Encryption
      AES 128 192 256
      ChaCha20
      Blowfish
    Auth and passwords
      HMAC
      PBKDF2 scrypt
    Platforms
      iOS macOS
      Linux Android
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Hash user passwords securely using scrypt or PBKDF2 before storing them in a database

USE CASE 2

Encrypt and decrypt data using AES-256-GCM for secure local storage or network transmission in an iOS app

USE CASE 3

Verify file integrity by computing a SHA-256 hash and comparing it before and after transfer

USE CASE 4

Authenticate API messages using HMAC to detect tampering in transit

Tech stack

Swift

Getting it running

Difficulty · easy Time to first run · 30min

In plain English

CryptoSwift is a collection of cryptographic tools written entirely in Swift, Apple's programming language for iOS, macOS, and related platforms. Cryptography is the practice of encoding and verifying data so that only authorized parties can read it. This library gives Swift developers a way to use those techniques without relying on platform-specific system libraries, since the entire implementation is written in pure Swift and works on Apple platforms, Linux, and Android. The library covers a wide range of standard cryptographic operations. For hashing, it includes MD5, SHA-1, several variants of SHA-2, and SHA-3. Hashing takes any data and produces a fixed-length fingerprint, it is commonly used to verify that a file has not changed or to store passwords safely. For encryption and decryption, it supports AES (with key sizes of 128, 192, and 256 bits), ChaCha20, Rabbit, and Blowfish. AES is the most widely used symmetric encryption standard in the world. The library also supports RSA, which is a public-key algorithm used when two parties need to exchange encrypted data without sharing a secret password first. Beyond those core algorithms, CryptoSwift provides message authenticators (tools that verify a message has not been tampered with), password hashing functions (PBKDF2, scrypt, and others that are specifically designed to be slow so that guessing passwords is impractical), and a range of cipher modes that control exactly how block encryption algorithms process data in sequence. The library is installed through Swift Package Manager, Apple's standard tool for adding dependencies to Swift projects. You add a few lines to your package configuration file and the source code is pulled in automatically. A prebuilt binary format is also available for manual Xcode integration. The README includes a short section on recommended defaults, advising developers to prefer authenticated encryption modes like AES-GCM or ChaCha20-Poly1305 for new work, to avoid older algorithms like MD5 and SHA-1 except for compatibility with legacy systems, and to use a unique initialization value for every encryption operation. These are practical guidelines for using the library correctly rather than just technically.

Copy-paste prompts

Prompt 1
Using CryptoSwift, help me encrypt a string with AES-256 in GCM mode in Swift and decrypt it again, include the key and nonce setup.
Prompt 2
Help me use CryptoSwift to hash a user password with PBKDF2 before storing it, and verify it again on login, show the full Swift code.
Prompt 3
Using CryptoSwift in a Swift Package Manager project, help me compute a SHA-256 hash of a file and display it as a hex string.
Prompt 4
Help me set up CryptoSwift via Swift Package Manager in Xcode and use ChaCha20-Poly1305 to encrypt data being sent to an API.
Prompt 5
Using CryptoSwift, help me generate an HMAC-SHA256 signature for an API request body to prove it has not been tampered with.
Open on GitHub → Explain another repo

← krzyzanowskim on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.