Read my answer here Importing CommonCrypto in a Swift framework

Overview

Arcane

❤️ Support my apps ❤️

❤️ ❤️ 😇 😍 🤘 ❤️ ❤️

CommonCrypto in Swift

CI Status Version Carthage Compatible License Platform

Description

Read my answer here Importing CommonCrypto in a Swift framework

Features

  • Work on NSData, String
  • Message Digest, SHA, HMAC, Base64
  • Hash Algorithm: MD2, MD4, MD5, SHA1, SHA256, SHA224, SHA384, SHA512

Hash

Hash.MD5("https://www.google.com/logos/doodles/2016/parents-day-in-korea-5757703554072576-hp2x.jpg") // 0dfb10e8d2ae771b3b3ed4544139644e
Hash.SHA246("https://www.google.com/logos/doodles/2016/parents-day-in-korea-5757703554072576-hp2x.jpg") // cb051d58a60b9581ff4c7ba63da07f9170f61bfbebab4a39898432ec970c3754

HMAC

HMAC.SHA1("https://www.google.com/logos/doodles/2016/parents-day-in-korea-5757703554072576-hp2x.jpg", key: "google") // 5f4474c8872d73c1490241ab015f6c672c6dcdc8

Base64

SHA1("https://www.google.com/logos/doodles/2016/parents-day-in-korea-5757703554072576-hp2x.jpg", key: "google") // X0R0yIctc8FJAkGrAV9sZyxtzcg=

AES

let _ = AES.encrypt("string", key: "secret")
let _ = AES.decrypt(data, key: keyData)

Installation

Arcane is distributed using the Swift Package Manager. To install it into a project, add it as a dependency within your Package.swift manifest:

let package = Package(
    ...
    dependencies: [
        .package(url: "https://github.com/onmyway133/Arcane.git", from: "3.0.0")
    ],
    ...
)

Then import Arcane in your project

import Arcane

Author

Khoa Pham, [email protected]

Contributing

We would love you to contribute to Arcane, check the CONTRIBUTING file for more info.

License

Arcane is available under the MIT license. See the LICENSE file for more info.

Comments
  • Header '/usr/include/CommonCrypto/CommonCrypto.h' not found

    Header '/usr/include/CommonCrypto/CommonCrypto.h' not found

    Whenever I try to compile a project using Arcane I get the following error on CCommonCrypto/module.modulemap:

    (...)/Pods/Arcane/Sources/CCommonCrypto/module.modulemap:2:10: Header '/usr/include/CommonCrypto/CommonCrypto.h' not found

    I'm using it as a pod dependecy. What am I doing wrong?

    opened by fpg1503 20
  • Warning about unsafe code

    Warning about unsafe code

      static func hash(_ data: Data, crypto: Crypto) -> Data {
        var buffer = Array<UInt8>(repeating: 0, count: Int(crypto.length))
        crypto.method(data: (data as NSData).bytes, length: UInt32(data.count), buffer: &buffer)
    
        return Data(bytes: UnsafePointer<UInt8>(buffer), count: buffer.count)
      }
    

    The last line results in warning:

    Initialization of 'UnsafePointer<UInt8>' results in a dangling pointer
    - Implicit argument conversion from '[UInt8]' to 'UnsafePointer<UInt8>' produces a pointer valid only for the duration of the call to 'init(_:)'
    - the 'withUnsafeBufferPointer' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope
    

    Anyone knows how to rewrite this..? It's beyond me.

    opened by radianttap 5
  • Add SPM support for Xcode 11 beta

    Add SPM support for Xcode 11 beta

    Adds version 5.1 Package.swift in order to import Arcane into Xcode 11 beta Apple have also released CryptoKit

    However it does not support HMAC.SHA1 which is why I currently rely on Arcane

    What Arcane SPM integration looks like in Xcode: Screen Shot 2019-06-07 at 10 27 49 pm

    Running tests via swift test now works (tests still work and pass in Xcode):

    % swift test
    [11/11] Linking ArcanePackageTests
    Test Suite 'All tests' started at 2019-06-07 22:35:29.762
    Test Suite 'ArcanePackageTests.xctest' started at 2019-06-07 22:35:29.762
    Test Suite 'Tests' started at 2019-06-07 22:35:29.763
    Test Case '-[ArcaneTests.Tests testAESWithData]' started.
    Test Case '-[ArcaneTests.Tests testAESWithData]' passed (0.323 seconds).
    Test Case '-[ArcaneTests.Tests testAESWithString]' started.
    Test Case '-[ArcaneTests.Tests testAESWithString]' passed (0.000 seconds).
    Test Case '-[ArcaneTests.Tests testBase64WithData]' started.
    Test Case '-[ArcaneTests.Tests testBase64WithData]' passed (0.000 seconds).
    Test Case '-[ArcaneTests.Tests testBase64WithString]' started.
    Test Case '-[ArcaneTests.Tests testBase64WithString]' passed (0.000 seconds).
    Test Case '-[ArcaneTests.Tests testHashWithData]' started.
    Test Case '-[ArcaneTests.Tests testHashWithData]' passed (0.000 seconds).
    Test Case '-[ArcaneTests.Tests testHashWithString]' started.
    Test Case '-[ArcaneTests.Tests testHashWithString]' passed (0.001 seconds).
    Test Case '-[ArcaneTests.Tests testHMAC]' started.
    Test Case '-[ArcaneTests.Tests testHMAC]' passed (0.001 seconds).
    Test Case '-[ArcaneTests.Tests testHMACWithDigest]' started.
    Test Case '-[ArcaneTests.Tests testHMACWithDigest]' passed (0.000 seconds).
    Test Case '-[ArcaneTests.Tests testObfuscator]' started.
    Test Case '-[ArcaneTests.Tests testObfuscator]' passed (0.000 seconds).
    Test Suite 'Tests' passed at 2019-06-07 22:35:30.090.
    	 Executed 9 tests, with 0 failures (0 unexpected) in 0.327 (0.327) seconds
    Test Suite 'ArcanePackageTests.xctest' passed at 2019-06-07 22:35:30.090.
    	 Executed 9 tests, with 0 failures (0 unexpected) in 0.327 (0.328) seconds
    Test Suite 'All tests' passed at 2019-06-07 22:35:30.090.
    	 Executed 9 tests, with 0 failures (0 unexpected) in 0.327 (0.328) seconds
    

    Testing carthage update on branch:

    % carthage update
    *** Fetching Arcane
    *** Checking out Arcane at "cec1ac4435a2e8828cb4af4560de1f64a4309824"
    *** xcodebuild output can be found in /var/folders/0d/jw4jdgs14ln2ljdl9h439zd40000gn/T/carthage-xcodebuild.izU4wP.log
    *** Building scheme "Arcane-watchOS" in Arcane.xcodeproj
    *** Building scheme "Arcane-tvOS" in Arcane.xcodeproj
    *** Building scheme "Arcane-iOS" in Arcane.xcodeproj
    *** Building scheme "Arcane-macOS" in Arcane.xcodeproj
    

    Testing pod install on branch:

    adamcampbell@Adams-MBP TestArcanePods % pod install
    Analyzing dependencies
    Pre-downloading: `Arcane` from `https://github.com/adamjcampbell/Arcane`, branch `spm-support`
    Setting up CocoaPods master repo
      $ /usr/local/bin/git clone https://github.com/CocoaPods/Specs.git --progress -- master
      Cloning into 'master'...
      remote: Enumerating objects: 23835, done.        
      remote: Counting objects: 100% (23835/23835), done.        
      remote: Compressing objects: 100% (11913/11913), done.        
      remote: Total 3205154 (delta 13297), reused 19652 (delta 10990), pack-reused 3181319
      Receiving objects: 100% (3205154/3205154), 656.66 MiB | 1.91 MiB/s, done.
      Resolving deltas: 100% (1913231/1913231), done.
      Checking out files: 100% (334253/334253), done.
    Setup completed
    Downloading dependencies
    Installing Arcane (2.1)
    Generating Pods project
    Integrating client project
    
    [!] Please close any current Xcode sessions and use `TestArcanePods.xcworkspace` for this project from now on.
    Sending stats
    Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.
    
    opened by adamjcampbell 5
  • error

    error

    hello

    when i try to install via CocoaPods

    [!] Error installing CommonCryptoSwift
    [!] /usr/bin/git clone https://github.com/AlexLittlejohn/CommonCryptoSwift.git /var/folders/8v/hf4f88fs4n5f9v98vx80xplr0000gn/T/d20160629-2022-1i88eeg --template= --single-branch --depth 1 --branch 1.0.1
    
    Cloning into '/var/folders/8v/hf4f88fs4n5f9v98vx80xplr0000gn/T/d20160629-2022-1i88eeg'...
    remote: Repository not found.
    fatal: repository 'https://github.com/AlexLittlejohn/CommonCryptoSwift.git/' not found
    

    regards

    opened by SebastienGracia 4
  • Refactor that using this is more natually

    Refactor that using this is more natually

    Old method is weird.👻 Data generator by passing dot is more useful and flexible.👍 String should not write so many method. Just use data extension

    base64
    base64String
    hexString
    

    let developer choose.

    let str = "aa"
    str.MD5?.hexString
    str.MD5?.base64String
    str.MD5?.base64
    
    opened by wolfcon 2
  • Expose digest type for HMAC generation

    Expose digest type for HMAC generation

    I needed the base64 digest result of an HMAC encryption so I can generate JWT tokens (http://jwt.io), but Arcane was hard-coded to hex.

    This PR exposes the option to choose hex or base64 digest for HMAC results:

    HMAC.SHA256(string, key: key, digest: .hex) //Default
    HMAC.SHA256(string, key: key, digest: .base64)
    

    See how other languages natively expose this option and some online encryption results that returns both digests.

    With this new DigestType enum, maybe you can delete Base64 and use this API instead:

    Hash.SHA256(string, key: key, digest: .hex) //Default
    Hash.SHA256(string, key: key, digest: .base64)
    

    I hope this helps and makes sense. Thanks for a great library! 👍

    opened by basememara 2
  • How to lint this pod?

    How to lint this pod?

    Hi, I'm trying to integrate CommonCrypto into my Cocoapods project, I found yours and see how you do it, but when i do pod lib lint, it return error no such module 'CCommonCrypto', so how can you lint and upload to pod base?

    opened by TienVu-PW 2
  • Require Only App-Extension-Safe API

    Require Only App-Extension-Safe API

    I'm trying to use Arcane in a Swift framework that is used in iOS extensions like Today, Notifications, etc. However, I'm getting a warning in Xcode:

    ld: warning: linking against a dylib which is not safe for use in application extensions: /Users/.../Arcane.framework/Arcane
    

    Can you please enable Require Only App-Extension-Safe API in the build settings?

    opened by basememara 2
  • SPM: dependency graph is unresolvable

    SPM: dependency graph is unresolvable

    I tried to add Arcane to a project with the following Package.swift created by swift package init:

    // swift-tools-version:5.0
    
    import PackageDescription
    
    let package = Package(
        name: "AesEverywhere",
        dependencies: [
            .package(url: "https://github.com/onmyway133/Arcane.git", from: "2.1.1")
        ],
        targets: [
            .target(
                name: "AesEverywhere",
                dependencies: ["Arcane"])
        ]
    )
    

    swift build gets this result:

    Updating https://github.com/onmyway133/Arcane.git
    error: dependency graph is unresolvable; found these conflicting requirements:
    
    Dependencies: 
        https://github.com/onmyway133/Arcane.git @ 2.1.1..<3.0.0
    
    

    Can you help me what is wrong?

    opened by mervick 1
  • Fix test info plist paths

    Fix test info plist paths

    Seems in my haste in #23 I didn't assign the correct info plists for the test targets. However the plists seem to be functionally duplicates so the tests still pass as is. This PR corrects the paths for correctness/completeness

    opened by adamjcampbell 1
  • Remove CommonCrypto script in podspec

    Remove CommonCrypto script in podspec

    Apple provides a Swift module for CommonCrypto starting with Xcode 10. So the script_phase is no longer needed in the pod spec. This was causing a build issue with the error: redefinition of module 'CommonCrypto'.

    opened by earlgaspard 1
Releases(3.0.0)
Owner
Khoa
Check my apps https://onmyway133.com/apps
Khoa
Elegant Swift interface to access the CommonCrypto routines

SCrypto [Overview • Requirements • Installation • Usage • Alternatives • Licence] Overview SCrypto provides neat Swift interface to access the CommonC

Max 39 Mar 31, 2022
A framework for the JOSE standards JWS, JWE, and JWK written in Swift.

JOSESwift is a modular and extensible framework for the JOSE standards JWS, JWE, and JWK written in Swift. ?? Please note that this implementation of

Airside Mobile, Inc. 162 Dec 15, 2022
Easy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.

Themis provides strong, usable cryptography for busy people General purpose cryptographic library for storage and messaging for iOS (Swift, Obj-C), An

Cossack Labs 1.6k Dec 30, 2022
A wrapper for Apple's Common Crypto library written in Swift.

IDZSwiftCommonCrypto A Swift wrapper for Apple's CommonCrypto library. IDZSwiftCommonCrypto works with both CocoaPods and Cathage. For more details on

idz 472 Dec 12, 2022
A pure Swift implementation of MD5

SwiftMD5 SwiftMD5 is a pure Swift implementation for the MD5 algorithm. Usage import SwiftMD5 "The quick brown fox jumps over the lazy dog".md5 // "9

Matthew Purland 11 Sep 25, 2021
🍕 MD5 in pure Swift

SwiftHash ❤️ Support my app ❤️ Push Hero - pure Swift native macOS application to test push notifications Quick Access - Organise files in the Mac men

Khoa 207 Dec 24, 2022
A tiny and easy to use Swift class to encrypt strings using HMAC algorithms.

#Sweet HMAC SweetHMAC is a tiny and easy to use Swift class to encrypt strings using HMAC algorithms. A special thanks to jernejstrasner for shared HM

Jan Cássio 37 Jul 27, 2022
RSA public/private key encryption in Swift

SwiftyRSA Maintainer(s): @ikeith Public key RSA encryption in Swift. SwiftyRSA is used in the Scoop iOS app to encrypt driver license numbers before s

Scoop 1.1k Jan 5, 2023
Enigma encryption in Swift

?????????????????? ?????????? // Will create an Enigma with an empty plugboard, rotors I, II, III and reflector B (wide). let enigma = Enigma() // Wil

Joakim Gyllström 113 Dec 16, 2022
CryptoSwift is a growing collection of standard and secure cryptographic algorithms implemented in Swift

CryptoSwift Crypto related functions and helpers for Swift implemented in Swift. (#PureSwift) Note: The main branch follows the latest currently relea

Marcin Krzyzanowski 9.4k Jan 9, 2023
Simple and secure hashing in Swift with the SipHash algorithm

SipHash ⚠️ WARNING This package has been obsoleted by the Hasher type and the Hashable.hash(into:) requirement introduced in Swift 4.2. Using this pac

null 262 Dec 19, 2022
CCCryptor (AES encryption) wrappers for iOS and Mac in Swift. -- For ObjC, see RNCryptor/RNCryptor-objc

RNCryptor Cross-language AES Encryptor/Decryptor data format. The primary targets are Swift and Objective-C, but implementations are available in C, C

null 3.3k Jan 7, 2023
Virgil Crypto stack Objective-C/Swift

Virgil Crypto Library Objective-C/Swift Introduction | Library purposes | Installation | Usage examples | Docs | License | Contacts Introduction Virgi

Virgil Security, Inc. 31 Oct 12, 2022
Kind of tired to need an Android Device on me, just to read manga, so here we are.

Dokusho Kind of tired to need an Android Device on me, just to read manga, so here we are. I am going to prioritize feature based on how I feel and no

Stephan Deumier 13 Oct 10, 2022
TelegramStickersImport — Telegram stickers importing SDK for iOS

TelegramStickersImport — Telegram stickers importing SDK for iOS TelegramStickersImport helps your users import third-party programaticaly created sti

null 35 Oct 26, 2022
The "Ask Me" is simple iOS application which shows answer on the screen everytime when the user press the ask button

The "Ask Me" is simple iOS application which shows answer on the screen everytime when the user press the ask button. This application is build and design by Chetan Parate using Xcode and Swift.

Chetan Parate 0 Oct 27, 2021
A few drop-in SwiftUI components for easily importing and thumb-nailing files

FilesUI A few drop-in SwiftUI components for easily importing and thumb-nailing files Usage 1. Import Files To import files you can use the FileImport

Brianna Zamora 3 Oct 19, 2022
iOS/macOS media picker for importing images and videos in SwiftUI

iOS/macOS media picker for importing images and videos in SwiftUI.

Mobile Development Club 13 Dec 30, 2022
Wordle-solver - A little command line app for finding the answer to Wordle

A little command line app for finding the answer to Wordle puzzles, written in S

Dalton Claybrook 6 Nov 2, 2022
TapLetterGuess - Find the answer by combining words

TapLetterGuess Find the answer by combining words.

Ahmet Onur Sahin 3 Apr 18, 2022