Swiftpack.co - Package - VirgilSecurity/sdk-x

Virgil Security Objective-C/Swift SDK

Build Status CocoaPods Compatible Carthage compatible Platform GitHub license

Introduction | SDK Features | Installation | Usage Examples | Docs | Support

Introduction

Virgil Security provides a set of APIs for adding security to any application. In a few simple steps you can encrypt communication, securely store data, provide passwordless login, and ensure data integrity.

The Virgil SDK allows developers to get up and running with Virgil API quickly and add full end-to-end security to their existing digital solutions to become HIPAA and GDPR compliant and more.

SDK Features

Installation

Virgil SDK is provided as a set of frameworks. These frameworks are distributed via Carthage and CocoaPods. Also in this guide, you find one more package called VirgilCrypto (Virgil Crypto Library) that is used by the SDK to perform cryptographic operations.

All frameworks are available for:

  • iOS 9.0+
  • macOS 10.10+
  • 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 VirgilSDK into your Xcode project using CocoaPods, specify it in your Podfile:

target '<Your Target Name>' do
  use_frameworks!

  pod 'VirgilCryptoApiImpl', '~> 3.2.0'
  pod 'VirgilSDK', '~> 5.4.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 VirgilSDK 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/sdk-x" ~> 5.4.0
github "VirgilSecurity/crypto-x" ~> 3.2.0

Linking against prebuilt binaries

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

$ carthage update --no-use-binaries

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

Building for iOS/tvOS/watchOS

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

  • VirgilSDK
  • VirgilCryptoAPI
  • VirgilCryptoApiImpl
  • VirgilCrypto
  • VSCCrypto

On your application targets’ “Build Phases” settings tab, click the “+” icon and choose “New Run Script Phase.” Create a Run Script in which you specify your shell (ex: /bin/sh), add the following contents to the script area below the shell:

/usr/local/bin/carthage copy-frameworks

and add the paths to the frameworks you want to use under “Input Files”, e.g.:

$(SRCROOT)/Carthage/Build/iOS/VirgilSDK.framework
$(SRCROOT)/Carthage/Build/iOS/VirgilCryptoAPI.framework
$(SRCROOT)/Carthage/Build/iOS/VirgilCryptoAPIImpl.framework
$(SRCROOT)/Carthage/Build/iOS/VirgilCrypto.framework
$(SRCROOT)/Carthage/Build/iOS/VSCCrypto.framework
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:

  • VirgilSDK
  • VirgilCryptoAPI
  • VirgilCryptoApiImpl
  • VirgilCrypto
  • VSCCrypto

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 corresponding dSYM file.

Integrating as subproject

It is possible to use carthage just for fetching the right sources for further integration into your project. Run following command:

$ carthage update --no-build

This will fetch dependencies into a Carthage/Checkouts folder inside your project's folder. Then, drag and drop VirgilCrypto.xcodeproj, VirgilCryptoAPI.xcodeproj and VirgilSDK.xcodeproj from corresponding folders inside Carthage/Checkouts folder to your Xcode Project Navigator sidebar.

Next, on your application target's “General” settings tab, in the “Embedded Binaries” section add the following frameworks from subprojects:

  • VirgilSDK
  • VirgilCryptoAPI
  • VirgilCryptoApiImpl
  • VirgilCrypto
  • VSCCrypto

Usage Examples

Before starting practicing with the usage examples be sure that the SDK is configured. Check out our SDK configuration guides for more information.

Generate and publish user's Cards with Public Keys inside on Cards Service

Use the following lines of code to create and publish a user's Card with Public Key inside on Virgil Cards Service:

import VirgilSDK
import VirgilCryptoApiImpl

// use Virgil Crypto
let crypto = VirgilCrypto()

// generate a user's key pair
let keyPair = try! crypto.generateKeyPair()

// save a private key into key storage
try! privateKeyStorage.store(privateKey: keyPair.privateKey, name: "Alice", meta: nil)

// publish user's card on the Cards Service
cardManager.publishCard(privateKey: keyPair.privateKey, publicKey: keyPair.publicKey).start { result in
    switch result {
        // Card is created
        case .success(let card): break
        // Error occured
        case .failure(let error): break
    }
}

Sign then encrypt data

Virgil SDK lets you use a user's Private key and his or her Cards to sign, then encrypt any kind of data.

In the following example, we load a Private Key from a customized Key Storage and get recipient's Card from the Virgil Cards Services. Recipient's Card contains a Public Key on which we will encrypt the data and verify a signature.

import VirgilSDK
import VirgilCryptoApiImpl

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

// prepare a user's private key
let alicePrivateKeyEntry = try! privateKeyStorage.load(withName: "Alice")
let alicePrivateKey = alicePrivateKeyEntry.privateKey as! VirgilPrivateKey

// using cardManager search for user's cards on Cards Service
cardManager.searchCards(identity: "Bob").start { result in
    switch result {
    // Cards are obtained
    case .success(let cards):
        let bobRelevantCardsPublicKeys = cards
            .map { $0.publicKey } as! [VirgilPublicKey]

        // sign a message with a private key then encrypt on a public key
        let encryptedData = try! crypto.signThenEncrypt(dataToEncrypt, with: alicePrivateKey,
                                                        for: bobRelevantCardsPublicKeys)

    // Error occured
    case .failure(let error): break
    }
}

Decrypt then verify data

Once the Users receive the signed and encrypted message, they can decrypt it with their own Private Key and verify signature with a Sender's Card:

import VirgilSDK
import VirgilCryptoApiImpl

// prepare a user's private key
let bobPrivateKeyEntry = try! privateKeyStorage.load(withName: "Bob")
let bobPrivateKey = bobPrivateKeyEntry.privateKey as! VirgilPrivateKey

// using cardManager search for user's cards on Cards Service
cardManager.searchCards(identity: "Alice").start { result in
    switch result {
    // Cards are obtained
    case .success(let cards):
        let aliceRelevantCardsPublicKeys = cards.map { $0.publicKey } as! [VirgilPublicKey]

        // decrypt with a private key and verify using a public key
        let decryptedData = try! crypto.decryptThenVerify(encryptedData, with: bobPrivateKey,
                                                          usingOneOf: aliceRelevantCardsPublicKeys)

    // Error occured
    case .failure(let error): break
    }
}

Docs

Virgil Security has a powerful set of APIs, and the documentation below can get you started today.

In order to use the Virgil SDK with your application, you will need to first configure your application. By default, the SDK will attempt to look for Virgil-specific settings in your application but you can change it during SDK configuration.

License

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

Support

Our developer support team is here to help you. Find out more information on our Help Center.

You can find us on Twitter or send us email support@VirgilSecurity.com.

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

Github

link
Stars: 19
Help us keep the lights on

Dependencies

Used By

Total: 0

Releases

5.4.1 - Oct 9, 2018

Fixed

  • Carthage release binaries on github

5.4.0 - Oct 9, 2018

Fixes

  • Fixed KeychainStorage.retrieveAllEntries() bug when external libraries also use Keychain
  • Small fixes

Changed

  • Migrated to Xcode 10 / Swift 4.2

5.3.0 - Jul 10, 2018

Added

  • KeychainStorage

5.2.0 - Jun 27, 2018

Added

  • Made part of API public
  • Improved ServiceRequest API
  • Result.getResult now rethrows error
  • Added static functions to CardManager

Fixed

  • Made embedded callback escaping in Jwt Providers

5.1.1 - Jun 18, 2018

Fixed

  • Http headers keys are now compared case-insensitively in accordance with RFC 2616.