Giter Club home page Giter Club logo

crypto's Introduction

Crypto

Version Swift Version Carthage compatible

Simple CommonCrypto wrapper for Swift for macOS, iOS, watchOS, and tvOS with Carthage support.

Released under the MIT license. Enjoy.

Installation

Carthage is the recommended way to install Crypto. Add the following to your Cartfile:

github "soffes/Crypto"

Note: this library depends on CommonCrypto, so you'll need to add both Crypto and CommonCrypto to your project.

Documentation

Currently, only digest and HMAC are supported.

Digest

There are extensions for Data and String for convenience:

import Crypto

"sam".sha1 // "f16bed56189e249fe4ca8ed10a1ecae60e8ceac0"
data.sha1  // <Data …>

MD2, MD4, MD5, SHA1, SHA224, SHA256, SHA384, SHA512 are available.

You can also use Digest directly:

Digest.md5(bytes: data.bytes, length: data.length) // [UInt8]

HMAC

HMAC in CommonCrypto is also supported.

HMAC.sign(message: "sam", algorithm: .sha1, key: "secret") // 1a90fa4e73686dfca75f5411d9fb81951edf1292

HMAC.sign(data: messageData, algorithm: .sha1, key: keyData) // <Data …>

MD5, SHA1, SHA224, SHA256, SHA384, SHA512 are the available algorithms.

Roadmap

This is a work in progress.

  • Cryptor
  • Digest
  • HMAC
  • Key Derivation
  • Random
  • Symmetric Key Wrap

crypto's People

Contributors

addisonwebb avatar jangorman avatar kangaroo5383 avatar mbuchetics avatar nickygerritsen avatar paulyoung avatar pebble8888 avatar soffes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

crypto's Issues

Update to Swift 5

Currently when building with Swift 5 (XCode 10.2), Crypto uses some older APIs which are now deprecated in Swift 5.

Installation

Since we don't use Carthage, It would be great to add a few lines explaining how to add this manually to project

How do I mine bitcoins?

Can wrap my head around how to make bitcoin or any other cryptocurrency in swift with this library. Can you please add an example? 💰

ld: warning: directory not found for option

Hi,

I am getting error while performing carthage update on project. Cartfile contains only

github "soffes/Crypto"

The error:

ld: warning: directory not found for option '-L/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS2.2.sdk/usr/lib/system' ld: warning: directory not found for option '-L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk/usr/lib/system' ld: warning: directory not found for option '-L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk/usr/lib/system'

Occasionally without any reason I am also getting:

** CLEAN FAILED **

The following build commands failed:
Check dependencies
(1 failure)
** BUILD FAILED **

The following build commands failed:
Check dependencies
(1 failure)
ld: warning: directory not found for option '-L/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS2.2.sdk/usr/lib/system'
A shell task (/usr/bin/xcrun xcodebuild -project /Users/user/Downloads/ios-sdk/Carthage/Checkouts/Crypto/Crypto.xcodeproj -scheme Crypto-tvOS -configuration Release -sdk appletvos ONLY_ACTIVE_ARCH=NO BITCODE_GENERATION_MODE=bitcode CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES clean build) failed with exit code 65:
** CLEAN FAILED **

The following build commands failed:
Check dependencies
(1 failure)
** BUILD FAILED **

The following build commands failed:
Check dependencies
(1 failure)

It's showing while doing "carthage update" but if I run it again it's showing the first error again.

I am running "carthage update" as normal user.

Test schemes?

Is there a reason the test schemes are not available? With the release of Xcode8 Beta 3 I had to make some changes(#20) and had to make my own scheme to run the existing test targets.

Linker Warnings

Hi,

building your Framework using carthage results in some warnings:

...:Crypto hibento$ carthage build --no-skip-current
*** xcodebuild output can be found in /var/folders/6s/vmhqrq757wd3k6lh11k39jsr0000gn/T/carthage-   xcodebuild.ue7mtk.log
*** Building scheme "Crypto-iOS" in Crypto.xcodeproj
*** Building scheme "CommonCrypto-OSX" in Crypto.xcodeproj
*** Building scheme "Crypto-OSX" in Crypto.xcodeproj
*** Building scheme "CommonCrypto-watchOS" in Crypto.xcodeproj
*** Building scheme "CommonCrypto-tvOS" in Crypto.xcodeproj
*** Building scheme "CommonCrypto-iOS" in Crypto.xcodeproj
*** Building scheme "Crypto-tvOS" in Crypto.xcodeproj
*** Building scheme "Crypto-watchOS" in Crypto.xcodeproj
ld: warning: directory not found for option '-L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk/usr/lib/system'
ld: warning: directory not found for option '-L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk/usr/lib/system'
ld: warning: directory not found for option '-L/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS2.2.sdk/usr/lib/system'

Modifying your Xcode build settings from
LIBRARY_SEARCH_PATHS = ("$(inherited)", "$(SDKROOT)/usr/lib/system");
to
LIBRARY_SEARCH_PATHS = "";
solves these warnings and the Framework still works for me.

watchOS target?

I am creating an SDK for a product we have and I'd like to add watchOS support to it.

Currently this is the only dependency that does not have a watchOS target.
Is it possible to add? Or is CommonCrypto not working on watchOS?

I could also try to create a PR myself if you like?

OSX doesn't compile?

Bitcode is enabled for the OSX build, but OSX doesn't support bitcode, I think this is why carthage is failing
I was able to build manually and use that

Manual Install

Ho can I Install it manually, i have some problems with that...

XCode 8.3 - Swift 3.1

Could you update to Swift 3.1 please?

Module compiled with Swift 3.0.1 cannot be imported in Swift 3.1: .../Carthage/Build/iOS/Crypto.framework/Modules/Crypto.swiftmodule/arm64.swiftmodule

Apple provide CommonCrypto swift module since Xcode 10.

Apple provide CommonCrypto swift module since Xcode 10.
So probably we no longer need soffes/CommonCrypto as dependency in Xcode10.

~$ ls -l /Applications/Xcode10GM.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/CommonCrypto/module.modulemap
-rw-r--r--  1 taiki  staff  258  8  5 03:50 /Applications/Xcode10GM.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/CommonCrypto/module.modulemap

~$ cat /Applications/Xcode10GM.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/CommonCrypto/module.modulemap
module CommonCrypto [system] [extern_c] {
  umbrella header "CommonCrypto.h"
  export *
  module * { export * }

  module Error {
      header "CommonCryptoError.h"
      export *
  }

  module Random {
      header "CommonRandom.h"
      export *
  }
}

Does not create md5 string

I guess the issue is in Data+Crypto file
I had to write 0 in place of index while interating thorugh pointer
var hex: String { var string = "" enumerateBytes { pointer, index, _ in for i in index..<pointer.count { string += String(format: "%02x", pointer[i]) } } return string }

Prebuilt binary via Carthage incompatible with Swift 3.0.1

This is as of XCode 8.1. Fix should be as simple as re-archiving the binary created by carthage.

If anybody else is having this problem, you can run the following to build from source and get around this problem.

carthage update --no-use-binaries

Carthage build failing for Xcode 8 beta 2

Cartfile: github "soffes/Crypto" "swift3"

Build Error:

** BUILD FAILED **


The following build commands failed:
    Ld .../Library/Developer/Xcode/DerivedData/Crypto-eedcgimieppepedcolqgjjntalol/Build/Products/Release-appletvos/Crypto.framework/Crypto normal arm64
(1 failure)
.../Carthage/Checkouts/Crypto/Crypto/String+Crypto.swift:65:73: warning: missing '.self' for reference to metatype of type 'UInt8'
/Users/davidkeegan/Development/Library/KGNCache/Carthage/Checkouts/Crypto/Crypto/String+Crypto.swift:65:73: warning: missing '.self' for reference to metatype of type 'UInt8'
.../Carthage/Checkouts/Crypto/Crypto/String+Crypto.swift:65:73: warning: missing '.self' for reference to metatype of type 'UInt8'
.../Carthage/Checkouts/Crypto/Crypto/String+Crypto.swift:65:73: warning: missing '.self' for reference to metatype of type 'UInt8'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
A shell task (/usr/bin/xcrun xcodebuild -project .../Carthage/Checkouts/Crypto/Crypto.xcodeproj -scheme Crypto-tvOS -configuration Release -sdk appletvos ONLY_ACTIVE_ARCH=NO BITCODE_GENERATION_MODE=bitcode CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES clean build) failed with exit code 65:
** BUILD FAILED **


The following build commands failed:
    Ld .../Library/Developer/Xcode/DerivedData/Crypto-eedcgimieppepedcolqgjjntalol/Build/Products/Release-appletvos/Crypto.framework/Crypto normal arm64
(1 failure)

Carthage Update fails on tvOS

Hi, I'm a bit of a newbie with this and Carthage, but it seems that "carthage update" command fails at tvOS stage like this:


$ carthage update
*** Cloning Crypto
*** Checking out Crypto at "v0.3.0"
*** xcodebuild output can be found in /var/folders/cv/y8tpg3v946x9h58ctz2yqg700000gn/T/carthage-xcodebuild.JUuVTA.log
*** Building scheme "CommonCrypto-watchOS" in Crypto.xcodeproj
*** Building scheme "CommonCrypto-iOS" in Crypto.xcodeproj
*** Building scheme "CommonCrypto-OSX" in Crypto.xcodeproj
*** Building scheme "Crypto-tvOS" in Crypto.xcodeproj
** CLEAN FAILED **

The following build commands failed:
Check dependencies
(1 failure)
A shell task (/usr/bin/xcrun xcodebuild -project /Users/…/Carthage/Checkouts/Crypto/Crypto.xcodeproj -scheme Crypto-tvOS -configuration Release -sdk appletvos ONLY_ACTIVE_ARCH=NO BITCODE_GENERATION_MODE=bitcode CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES clean build) failed with exit code 65:

As a result (I believe) the tvOS folder is missing from carthage/build. This is sad because I'd need CommonCrypto especially for tvOS. :)

I apologise if this is just my ignorance on some topic, or I'm missing something, but as of now I don't seem to get it going for tvOS by following Carthage installation guide.

Digest property return "" in Swift 3.1

All of the digest(MD2, MD4, MD5, SHA1, SHA224, SHA256, SHA384, SHA512) for String extension return "".

"sam".sha1 // ""

Crypto: 0.5.1
CommonCrypto: 1.1.0
Xcode: 8.3
Swift: 3.1

Bitcode Warning

Currently importing this with Xcode 7 / iOS 9 and getting the following warning:

ld: warning: URGENT: all bitcode will be dropped because 'Carthage/Build/iOS/CommonCrypto.framework/CommonCrypto' was built without bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. Note: This will be an error in the future.

Is this something that needs to be updated in the library or is this a Carthage issue?

Doubt : How to get sha1 of Data as a String

Right now we have methods which gives sha1 of Data as Data. So I have tried converting it into String by UTF8 Encoding & also ASCII, but it seems that both didn't produce the proper String.

How can I get sha1 as String for Data?

Zlib problem when building for emulator

Compiling for iOS device (or generic device) succeeds

When compiling for simulator, we get errors for redefinition of modules: 'Compression', 'Darwin', 'os', 'libkern'
The result of the error is: 'Could not build Objective-C module 'Zlib''

The redefinition happens because these modules are defined in both iOS and iOS simulator module maps, example of the error:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.1.sdk/usr/include/module.modulemap:1:8: error: redefinition of module 'Compression'
module Compression [system] [extern_c] {
       ^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/module.modulemap:1:8: note: previously defined here
module Compression [system] [extern_c] {

Really at a complete loss as to what to do here. I tried removing the simulator module maps but that caused other issues. Crypto worked in simulator for me before Zlib was added

Building randomly breaks with Carthage

If I use Crypto as a dependency buidling randomly breaks when running carthage update with the following in the log:

Build settings from command line:
    BITCODE_GENERATION_MODE = bitcode
    CODE_SIGN_IDENTITY = 
    CODE_SIGNING_REQUIRED = NO
    ONLY_ACTIVE_ARCH = NO
    SDKROOT = appletvos9.1

=== BUILD TARGET CommonCrypto-OSX OF PROJECT Crypto WITH CONFIGURATION Release ===

Check dependencies
target 'CommonCrypto-OSX' has bitcode disabled (ENABLE_BITCODE = NO), but it is required for the 'appletvos' platform

It seems it wants to build the OS X target for a tvos SDK, which of course fails.

I remember having this problem before and in one of my PR's I used to have fixed this by removing and recreating some (or all) targets in the project.

However because I redid that whole PR I forgot to do that again and forgot what it exactly was.

I might be able to fix it again, but was also wondering if other people have the same problem.

Console warning in Xcode 8 & Swift 3

I have been seeing this warning in Xcode 8 from the last two days. I am using Crypto in my Swift 3 project. I would like to know why this warning shows up and is there anything I have to worry about?

warning: Swift error in module Crypto.
Debug info from this module will be unavailable in the debugger.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.