Latest 1.0.1
Homepage https://github.com/msgrizz/KryptoSwift
License MIT
Platforms ios 8.0, osx 10.9, tvos 9.2, watchos 3.0, requires ARC
Authors

🔱 CommonCrypto in Swift, and more!

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

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)

Obfuscator

let obfuscator = Obfuscator(value: "").a.b.c.d.e.n1.n2.X.Y.Z // "abcde12XYZ"

Usign key generation

let str = "My little secret"
let password = AES256CBC.generatePassword()  // returns random 32 char string

// get AES-256 CBC encrypted string
let encrypted = AES256CBC.encryptString(str, password: password)

// decrypt AES-256 CBC encrypted string
let decrypted = AES256CBC.decryptString(encrypted!, password: password)

Using KryptoSwiftAES256

do {
      let digest = "hello world".data(using: .utf8)!
      let password = "foo"
      let salt = KryptoSwiftAES256.randomSalt()
      let iv = KryptoSwiftAES256.randomIv()
      let key = try KryptoSwiftAES256.createKey(password: password.data(using: .utf8)!, salt: salt)
      let aes = try KryptoSwiftAES256(key: key, iv: iv)
      let encrypted = try aes.encrypt(digest)
      let decrypted = try aes.decrypt(encrypted)

      print("Encrypted: (encrypted.hexString)")
      print("Decrypted: (decrypted.hexString)")
      print("Password: (password)")
      print("Key: (key.hexString)")
      print("IV: (iv.hexString)")
      print("Salt: (salt.hexString)")
      print(" ")

      print("#! /bin/sh")
      print("echo (digest.hexString) | xxd -r -p > digest.txt")
      print("echo (encrypted.hexString) | xxd -r -p > encrypted.txt")
      print("openssl aes-256-cbc -K (key.hexString) -iv (iv.hexString) -e -in digest.txt -out encrypted-openssl.txt")
      print("openssl aes-256-cbc -K (key.hexString) -iv (iv.hexString) -d -in encrypted.txt -out decrypted-openssl.txt")
    } catch {
      print("Failed")
      print(error)
    }

Installation

Arcane is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'KryptoSwift'

Arcane is also available through Carthage.
To install just write into your Cartfile:

github "msgrizz/KryptoSwift"

Author

Mihail Salari, [email protected]

Contributing

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

License

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

Latest podspec

{
    "name": "KryptoSwift",
    "summary": "CommonCrypto in Swift",
    "version": "1.0.1",
    "homepage": "https://github.com/msgrizz/KryptoSwift",
    "license": "MIT",
    "authors": {
        "Khoa Pham": "[email protected]"
    },
    "source": {
        "git": "https://github.com/msgrizz/KryptoSwift.git",
        "tag": "1.0.1"
    },
    "social_media_url": "https://fb.com/new.mihailsalari",
    "platforms": {
        "ios": "8.0",
        "osx": "10.9",
        "tvos": "9.2",
        "watchos": "3.0"
    },
    "requires_arc": true,
    "source_files": "Sources/**/*.swift",
    "preserve_paths": "CocoaPods/**/*",
    "pod_target_xcconfig": {
        "SWIFT_INCLUDE_PATHS[sdk=macosx*]": "$(PODS_ROOT)/KryptoSwift/CocoaPods/macosx",
        "SWIFT_INCLUDE_PATHS[sdk=iphoneos*]": "$(PODS_ROOT)/KryptoSwift/CocoaPods/iphoneos",
        "SWIFT_INCLUDE_PATHS[sdk=iphonesimulator*]": "$(PODS_ROOT)/KryptoSwift/CocoaPods/iphonesimulator",
        "SWIFT_INCLUDE_PATHS[sdk=appletvos*]": "$(PODS_ROOT)/KryptoSwift/CocoaPods/appletvos",
        "SWIFT_INCLUDE_PATHS[sdk=appletvsimulator*]": "$(PODS_ROOT)/KryptoSwift/CocoaPods/appletvsimulator",
        "SWIFT_INCLUDE_PATHS[sdk=watchos*]": "$(PODS_ROOT)/KryptoSwift/CocoaPods/watchos",
        "SWIFT_INCLUDE_PATHS[sdk=watchsimulator*]": "$(PODS_ROOT)/KryptoSwift/CocoaPods/watchsimulator",
        "SWIFT_VERSION": "4.0"
    }
}

Pin It on Pinterest

Share This