Virgil Crypto stack Objective-C/Swift

Overview

Virgil Crypto Library Objective-C/Swift

Build Status CocoaPods Compatible Carthage compatible Platform GitHub license

Introduction | Library purposes | Installation | Usage examples | Docs | License | Contacts

Introduction

Virgil Crypto Library Objective-C/Swift is a small, flexible and convenient wrapper for a variety of crypto algorithms. It can be used in a small microcontroller as well as in a high load server application. Also, it provides a bunch of custom hybrid algorithms that combine different crypto algorithms to solve common complex cryptographic problems in an easy way. That eliminates a requirement for developers to have strong cryptographic skills.

Virgil Security Objective-C/Swift Crypto Library uses Swift wrapper Virgil Security Crypto Library Wrapper over C library Virgil Security Crypto Library.

Library purposes

  • Asymmetric Key Generation
  • Encryption/Decryption of data and streams
  • Generation/Verification of digital signatures
  • Double Ratchet algorithm support
  • Post-quantum algorithms support: Round5 (encryption) and Falcon (signature)
  • Crypto for using Virgil Core SDK

Installation

VirgilCrypto is provided as a set of frameworks. These frameworks are distributed via Carthage and CocoaPods.

All frameworks are available for:

  • iOS 9.0+
  • macOS 10.9+
  • tvOS 9.0+
  • watchOS 2.0+

COCOAPODS

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate VirgilCrypto into your Xcode project using CocoaPods, specify it in your Podfile:

target '<Your Target Name>' do
  use_frameworks!

  pod 'VirgilCrypto', '~> 6.0.0'
end

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate VirgilCrypto into your Xcode project using Carthage, create an empty file with name Cartfile in your project's root folder and add following lines to your Cartfile

github "VirgilSecurity/virgil-crypto-x" ~> 6.0.0

Linking against prebuilt binaries

To link prebuilt frameworks to your app, run following command:

$ carthage update --use-xcframeworks

This will build each dependency or download a pre-compiled framework from github Releases.

Building for iOS/tvOS/watchOS

On your application target's “General” settings tab, in the “Linked Frameworks and Libraries” section, add following frameworks from the Carthage/Build folder inside your project's folder:

  • VirgilCrypto
  • VirgilCryptoFoundation
  • VSCCommon
  • VSCFoundation

Check Embed & sign for each.

Building for macOS

On your application target's “General” settings tab, in the “Embedded Binaries” section, drag and drop following frameworks from the Carthage/Build folder on disk:

  • VirgilCrypto
  • VirgilCryptoFoundation
  • VSCCommon
  • VSCFoundation

Additionally, you'll need to copy debug symbols for debugging and crash reporting on macOS.

On your application target’s “Build Phases” settings tab, click the “+” icon and choose “New Copy Files Phase”. Click the “Destination” drop-down menu and select “Products Directory”. For each framework, drag and drop the corresponding dSYM file.

Usage examples

Generate a key pair

Generate a private key using the default algorithm (EC_X25519):

import VirgilCrypto

let crypto = try! VirgilCrypto()
let keyPair = try! crypto.generateKeyPair()

Generate and verify a signature

Generate signature and sign data with a private key:

import VirgilCrypto

let crypto = try! VirgilCrypto()

// prepare a message
let messageToSign = "Hello, Bob!"
let dataToSign = messageToSign.data(using: .utf8)!

// generate a signature
let signature = try! crypto.generateSignature(of: dataToSign, using: senderPrivateKey)

Verify a signature with a public key:

import VirgilCrypto

let crypto = try! VirgilCrypto()

// verify a signature
let verified = try! crypto.verifySignature(signature, of: dataToSign, with: senderPublicKey)

Encrypt and decrypt data

Encrypt data with a public key:

import VirgilCrypto

let crypto = try! VirgilCrypto()

// prepare a message
let messageToEncrypt = "Hello, Bob!"
let dataToEncrypt = messageToEncrypt.data(using: .utf8)!

// encrypt the message
let encryptedData = try! crypto.encrypt(dataToEncrypt, for: [receiverPublicKey])

Decrypt the encrypted data with a Private Key:

import VirgilCrypto

let crypto = try! VirgilCrypto()

// prepare data to be decrypted
let decryptedData = try! crypto.decrypt(encryptedData, with: receiverPrivateKey)

// decrypt the encrypted data using a private key
let decryptedMessage = String(data: decryptedData, encoding: .utf8)!

Import and export keys

Export keys:

import VirgilCrypto

// generate a Key Pair
let crypto = VirgilCrypto()
let keyPair = try! crypto.generateKeyPair()

// export a Private key
let privateKeyData = try! crypto.exportPrivateKey(keyPair.privateKey, password: "YOUR_PASSWORD")
let privateKeyStr = privateKeyData.base64EncodedString()

// export a Public key
let publicKeyData = crypto.exportPublicKey(keyPair.publicKey)
let publicKeyStr = publicKeyData.base64EncodedString()

Import keys:

import VirgilCrypto

let crypto = VirgilCrypto()

let privateKeyStr = "MIGhMF0GCSqGSIb3DQEFDTBQMC8GCSqGSIb3DQEFDDAiBBBtfBoM7VfmWPlvyHuGWvMSAgIZ6zAKBggqhkiG9w0CCjAdBglghkgBZQMEASoEECwaKJKWFNn3OMVoUXEcmqcEQMZ+WWkmPqzwzJXGFrgS/+bEbr2DvreVgEUiLKrggmXL9ZKugPKG0VhNY0omnCNXDzkXi5dCFp25RLqbbSYsCyw="

let privateKeyData = Data(base64Encoded: privateKeyStr)!

// import a Private key
let privateKey = try! crypto.importPrivateKey(from: privateKeyData, password: "YOUR_PASSWORD")

//-----------------------------------------------------

let publicKeyStr = "MCowBQYDK2VwAyEA9IVUzsQENtRVzhzraTiEZZy7YLq5LDQOXGQG/q0t0kE="

let publicKeyData = Data(base64Encoded: publicKeyStr)!

// import a Public key
let publicKey = try! crypto.importPublicKey(from: publicKeyData)

Docs

License

This library is released under the 3-clause BSD License.

Support

Our developer support team is here to help you.

You can find us on Twitter or send us email [email protected].

Also, get extra help from our support team on Slack.

Comments
  • Building v3.2 with Carthage

    Building v3.2 with Carthage

    Hello,

    I am attempting to use Carthage to build version 3.2.3 this library and am encountering an error while building Using Xcode 11.0 / Swift 5.1.


    Xcode version: 11.0

    Swift version: 5.1

    Cartfile:

    github "VirgilSecurity/virgil-sdk-x" == 5.8.0
    github "VirgilSecurity/virgil-crypto-x" == 3.2.3
    

    Error:

    CompileSwift normal x86_64 (in target 'VirgilCrypto macOS' from project 'VirgilCrypto')
        cd /Users/ExampleApp/ios/Carthage/Checkouts/virgil-crypto-x
        /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c /Users/ExampleApp/ios/Carthage/Checkouts/virgil-crypto-x/VirgilCrypto/Source/Pythia/VirgilPythia.swift /Users/ExampleApp/ios/Carthage/Checkouts/virgil-crypto-x/VirgilCrypto/Source/Pythia/BlindResult.swift -emit-module-path /Users/Bryan/Library/Caches/org.carthage.CarthageKit/DerivedData/11.0_11A420a/virgil-crypto-x/3.2.3/Build/Intermediates.noindex/ArchiveIntermediates/VirgilCrypto\ macOS/IntermediateBuildFilesPath/VirgilCrypto.build/Release/VirgilCrypto\ macOS.build/Objects-normal/x86_64/VirgilCrypto.swiftmodule -emit-module-doc-path /Users/Bryan/Library/Caches/org.carthage.CarthageKit/DerivedData/11.0_11A420a/virgil-crypto-x/3.2.3/Build/Intermediates.noindex/ArchiveIntermediates/VirgilCrypto\ macOS/IntermediateBuildFilesPath/VirgilCrypto.build/Release/VirgilCrypto\ macOS.build/Objects-normal/x86_64/VirgilCrypto.swiftdoc -serialize-diagnostics-path /Users/Bryan/Library/Caches/org.carthage.CarthageKit/DerivedData/11.0_11A420a/virgil-crypto-x/3.2.3/Build/Intermediates.noindex/ArchiveIntermediates/VirgilCrypto\ macOS/IntermediateBuildFilesPath/VirgilCrypto.build/Release/VirgilCrypto\ macOS.build/Objects-normal/x86_64/VirgilCrypto\ macOS-master.dia -emit-objc-header-path /Users/Bryan/Library/Caches/org.carthage.CarthageKit/DerivedData/11.0_11A420a/virgil-crypto-x/3.2.3/Build/Intermediates.noindex/ArchiveIntermediates/VirgilCrypto\ macOS/IntermediateBuildFilesPath/VirgilCrypto.build/Release/VirgilCrypto\ macOS.build/Objects-normal/x86_64/VirgilCrypto-Swift.h -emit-dependencies-path /Users/Bryan/Library/Caches/org.carthage.CarthageKit/DerivedData/11.0_11A420a/virgil-crypto-x/3.2.3/Build/Intermediates.noindex/ArchiveIntermediates/VirgilCrypto\ macOS/IntermediateBuildFilesPath/VirgilCrypto.build/Release/VirgilCrypto\ macOS.build/Objects-normal/x86_64/VirgilCrypto\ macOS-master.d -target x86_64-apple-macos10.10 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -I /Users/Bryan/Library/Caches/org.carthage.CarthageKit/DerivedData/11.0_11A420a/virgil-crypto-x/3.2.3/Build/Intermediates.noindex/ArchiveIntermediates/VirgilCrypto\ macOS/BuildProductsPath/Release -F /Users/Bryan/Library/Caches/org.carthage.CarthageKit/DerivedData/11.0_11A420a/virgil-crypto-x/3.2.3/Build/Intermediates.noindex/ArchiveIntermediates/VirgilCrypto\ macOS/BuildProductsPath/Release -application-extension -g -import-underlying-module -module-cache-path /Users/Bryan/Library/Caches/org.carthage.CarthageKit/DerivedData/11.0_11A420a/virgil-crypto-x/3.2.3/ModuleCache.noindex -swift-version 4.2 -enforce-exclusivity=checked -O -serialize-debugging-options -Xcc -working-directory -Xcc /Users/ExampleApp/ios/Carthage/Checkouts/virgil-crypto-x -Xcc -I/Users/Bryan/Library/Caches/org.carthage.CarthageKit/DerivedData/11.0_11A420a/virgil-crypto-x/3.2.3/Build/Intermediates.noindex/ArchiveIntermediates/VirgilCrypto\ macOS/IntermediateBuildFilesPath/VirgilCrypto.build/Release/VirgilCrypto\ macOS.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/Bryan/Library/Caches/org.carthage.CarthageKit/DerivedData/11.0_11A420a/virgil-crypto-x/3.2.3/Build/Intermediates.noindex/ArchiveIntermediates/VirgilCrypto\ macOS/IntermediateBuildFilesPath/VirgilCrypto.build/Release/VirgilCrypto\ macOS.build/VirgilCrypto-generated-files.hmap -Xcc -I/Users/Bryan/Library/Caches/org.carthage.CarthageKit/DerivedData/11.0_11A420a/virgil-crypto-x/3.2.3/Build/Intermediates.noindex/ArchiveIntermediates/VirgilCrypto\ macOS/IntermediateBuildFilesPath/VirgilCrypto.build/Release/VirgilCrypto\ macOS.build/VirgilCrypto-own-target-headers.hmap -Xcc -I/Users/Bryan/Library/Caches/org.carthage.CarthageKit/DerivedData/11.0_11A420a/virgil-crypto-x/3.2.3/Build/Intermediates.noindex/ArchiveIntermediates/VirgilCrypto\ macOS/IntermediateBuildFilesPath/VirgilCrypto.build/Release/VirgilCrypto\ macOS.build/VirgilCrypto-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/Bryan/Library/Caches/org.carthage.CarthageKit/DerivedData/11.0_11A420a/virgil-crypto-x/3.2.3/Build/Intermediates.noindex/ArchiveIntermediates/VirgilCrypto\ macOS/IntermediateBuildFilesPath/VirgilCrypto.build/Release/VirgilCrypto\ macOS.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/Bryan/Library/Caches/org.carthage.CarthageKit/DerivedData/11.0_11A420a/virgil-crypto-x/3.2.3/Build/Intermediates.noindex/ArchiveIntermediates/VirgilCrypto\ macOS/IntermediateBuildFilesPath/VirgilCrypto.build/Release/VirgilCrypto\ macOS.build/VirgilCrypto-project-headers.hmap -Xcc -I/Users/Bryan/Library/Caches/org.carthage.CarthageKit/DerivedData/11.0_11A420a/virgil-crypto-x/3.2.3/Build/Intermediates.noindex/ArchiveIntermediates/VirgilCrypto\ macOS/BuildProductsPath/Release/include -Xcc -I/Users/Bryan/Library/Caches/org.carthage.CarthageKit/DerivedData/11.0_11A420a/virgil-crypto-x/3.2.3/Build/Intermediates.noindex/ArchiveIntermediates/VirgilCrypto\ macOS/IntermediateBuildFilesPath/VirgilCrypto.build/Release/VirgilCrypto\ macOS.build/DerivedSources-normal/x86_64 -Xcc -I/Users/Bryan/Library/Caches/org.carthage.CarthageKit/DerivedData/11.0_11A420a/virgil-crypto-x/3.2.3/Build/Intermediates.noindex/ArchiveIntermediates/VirgilCrypto\ macOS/IntermediateBuildFilesPath/VirgilCrypto.build/Release/VirgilCrypto\ macOS.build/DerivedSources/x86_64 -Xcc -I/Users/Bryan/Library/Caches/org.carthage.CarthageKit/DerivedData/11.0_11A420a/virgil-crypto-x/3.2.3/Build/Intermediates.noindex/ArchiveIntermediates/VirgilCrypto\ macOS/IntermediateBuildFilesPath/VirgilCrypto.build/Release/VirgilCrypto\ macOS.build/DerivedSources -Xcc -ivfsoverlay -Xcc /Users/Bryan/Library/Caches/org.carthage.CarthageKit/DerivedData/11.0_11A420a/virgil-crypto-x/3.2.3/Build/Intermediates.noindex/ArchiveIntermediates/VirgilCrypto\ macOS/IntermediateBuildFilesPath/VirgilCrypto.build/Release/VirgilCrypto\ macOS.build/unextended-module-overlay.yaml -module-name VirgilCrypto -num-threads 8 -o /Users/Bryan/Library/Caches/org.carthage.CarthageKit/DerivedData/11.0_11A420a/virgil-crypto-x/3.2.3/Build/Intermediates.noindex/ArchiveIntermediates/VirgilCrypto\ macOS/IntermediateBuildFilesPath/VirgilCrypto.build/Release/VirgilCrypto\ macOS.build/Objects-normal/x86_64/VirgilPythia.o -o /Users/Bryan/Library/Caches/org.carthage.CarthageKit/DerivedData/11.0_11A420a/virgil-crypto-x/3.2.3/Build/Intermediates.noindex/ArchiveIntermediates/VirgilCrypto\ macOS/IntermediateBuildFilesPath/VirgilCrypto.build/Release/VirgilCrypto\ macOS.build/Objects-normal/x86_64/BlindResult.o
    /Users/Bryan/Library/Caches/org.carthage.CarthageKit/DerivedData/11.0_11A420a/virgil-crypto-x/3.2.3/Build/Intermediates.noindex/ArchiveIntermediates/VirgilCrypto macOS/IntermediateBuildFilesPath/VirgilCrypto.build/Release/VSCCrypto macOS.build/module.modulemap:2:10: error: header 'pythia/pythia_buf.h' not found
      header "pythia/pythia_buf.h"
             ^
    /Users/ExampleApp/ios/Carthage/Checkouts/virgil-crypto-x/VirgilCrypto/Source/Pythia/VirgilPythia.swift:38:8: error: could not build Objective-C module 'VSCCrypto'
    import VSCCrypto
           ^
    
    ** ARCHIVE FAILED **
    
    
    The following build commands failed:
            CompileSwift normal x86_64
            CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
    (2 failures)
    

    Is this a problem due to Swift 5.1?

    opened by bryjch 10
  • Support for EC_SECP224K1 curve

    Support for EC_SECP224K1 curve

    Hi, Is it possible to add EC_SECP224K1 curve type? The C++ library has the support for this variant and I'm trying to add this curve in your wrapper. I am new to Cryptography and working with C++. I am struggling a lot in adding the support for this type of curve(EC_SECP224K1) in iOS. Your help/guidance will be much appreciated, Thanks.

    opened by deadshot2491 10
  • v6.0.0

    v6.0.0

    Added

    • Xcode 12.2+ support
    • Apple Silicon support

    Project

    • Use new format xcframeworks for dependencies
    • Bumped up test targets macOS requirement to 10.15.0 (Xcode 12 warnings)
    • Updated CI to latest Xcode & sdks

    Dependencies

    • Updated VirgilCryptoFoundation 0.15.2 --> 0.16.0

    Other

    • Updated LICENCE & Copyright
    opened by Ogerets 0
  • SPM support

    SPM support

    Hi!

    Is there any information about Swift Package Manager support ? Is there anything standing in the way of supporting SPM ?

    I would appreciate if you would add it!

    opened by Kukurijek 0
  • Problems with arm64 architecture on XCode 12

    Problems with arm64 architecture on XCode 12

    Hi!

    Into my project path '/Pods/VSCCrypto/Carthage/iOS/VSCCommon.framework/VSCCommon' I have a problem for architecture arm64 when compiling for simulator (no problem for devices).

    This seems to be related to the new apple processors for mac. By now I'm using this workarround https://github.com/aws-amplify/aws-sdk-ios/issues/2927#issuecomment-678818133 (executing in simulator with no problems). But your project should be granting compatibility to XCode 12 and new Macbooks when they get released.

    Thank you, Diego M.

    opened by canedo2 2
Releases(6.0.1)
Owner
Virgil Security, Inc.
Virgil Security, Inc. enables developers to eliminate passwords & encrypt everything, in hours, without having to become security experts.
Virgil Security, Inc.
Safe and easy to use crypto for iOS and macOS

Swift-Sodium Swift-Sodium provides a safe and easy to use interface to perform common cryptographic operations on macOS, iOS, tvOS and watchOS. It lev

Frank Denis 483 Jan 5, 2023
A simple and opinionated AES encrypt / decrypt Objective-C class that just works.

AESCrypt-ObjC - Simple AES encryption / decryption for iOS and OS X AESCrypt is a simple to use, opinionated AES encryption / decryption Objective-C c

Gurpartap Singh 782 Oct 12, 2022
Read my answer here Importing CommonCrypto in a Swift framework

Read my answer here Importing CommonCrypto in a Swift framework

Khoa 281 Sep 17, 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 generation, RSA, AES encryption/decryption, RSA sign/verify in Swift with CommonCrypto in iOS and OS X

SwCrypt Create public and private RSA keys in DER format let (privateKey, publicKey) = try! CC.RSA.generateKeyPair(2048) Convert them to PEM format l

soyer 695 Dec 8, 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
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
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
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
Virgil Core SDK allows developers to get up and running with Virgil Cards Service API quickly and add end-to-end security to their new or existing digital solutions to become HIPAA and GDPR compliant and more.

Virgil Core SDK Objective-C/Swift Introduction | SDK Features | Installation | Configure SDK | Usage Examples | Docs | Support Introduction Virgil Sec

Virgil Security, Inc. 27 Jul 26, 2022
Virgil PFS SDK Objective-C/Swift

Virgil SWIFT PFS SDK Introduction | SDK Features | Installation | Initialization | Chat Example | Register Users | Docs | Support Introduction Virgil

Virgil Security, Inc. 3 Mar 16, 2021
iOS client for the TradeOgre.com crypto-to-crypto trading platform

TradeOgre iOS Overview TradeOgre iOS is an iOS client for the TrageOgre.com website and crypto-exchange platform. I was looking for their iOS client,

Kyle Roucis 1 Feb 1, 2022
Swipe able, customizable card stack view, Tinder like card stack view based on UICollectionView. Cards UI

Swipable, customizable card stack view, Tinder like card stack view based on UICollectionView. Cards UI Сocoapods installation Add in your Podfile: po

Indy 850 Nov 17, 2022
JSPatch bridge Objective-C and Javascript using the Objective-C runtime. You can call any Objective-C class and method in JavaScript by just including a small engine. JSPatch is generally used to hotfix iOS App.

JSPatch 中文介绍 | 文档 | JSPatch平台 请大家不要自行接入 JSPatch,统一接入 JSPatch 平台,让热修复在一个安全和可控的环境下使用。原因详见 这里 JSPatch bridges Objective-C and JavaScript using the Object

bang 11.4k Jan 1, 2023
CryptoSwift - Crypto related functions and helpers for Swift implemented in Swift

CryptoSwift Crypto related functions and helpers for Swift implemented in Swift.

Kushal Shingote 2 Feb 6, 2022