Git Product home page Git Product logo

sodiumobjc's Introduction

SodiumObjc

Objective-C bindings for NaCL.

Build Status

License

MIT License. See LICENSE for more information.

Usage

Public-Key Cryptography

Both NSString and NSData have been augmented with public-key encryption/decryption methods via the NSString+Nacl and NSData+NACL categories.

Encryption

NSString *plainText = @"I am about to get encrypted.";
NACLAsymmetricKeyPair *sendersKeyPair = [NACLAsymmetricKeyPair keyPair];
NACLAsymmetricKeyPair *receiversKeyPair = [NACLAsymmetricKeyPair keyPair];
NACLNonce *nonce = [NACLNonce nonce];

NSData *encryptedData;
encryptedData = [plainText encryptedDataUsingPublicKey:sendersKeyPair.publicKey
                                            privateKey:receiversKeyPair.privateKey
                                                 nonce:nonce];

Decryption

plainText = [encryptedData decryptedTextUsingPublicKey:receiversKeyPair.publicKey
                                            privateKey:sendersKeyPair.privateKey];

Compatibility

The methods that perform public-key encryption pack the nonce data at the beginning of the encrypted data object. The methods that perform public-key decryption without an explicit nonce argument expect nonce data to be packed at the beginning of the receiver. The methods that perform public-key decryption with an explicit nonce argument expect nonce data to not be packed at the beginning of the receiver. This behavior is provided as a convenience so you don't have to maintain the nonce. Keep in mind that if you consume encrypted data on another platform (or any library other than SodiumObjc), you should remove the nonce.

NSData *encryptedData;
encryptedData = [[plainText encryptedDataUsingPublicKey:sendersKeyPair.publicKey
                                             privateKey:receiversKeyPair.privateKey
                                                  nonce:nonce] dataWithoutNonce];

NSMutableURLRequest *request = ...
request.HTTPBody = encryptedData;

Private-Key Cryptography

Both NSString and NSData have been augmented with secret-key encryption/decryption methods via the NSString+Nacl and NSData+NACL categories, as well.

Encryption

NSString *plainText = @"I am about to get encrypted.";
NACLSymmetricPrivateKey *privateKey = [NACLSymmetricPrivateKey privateKey];
NACLNonce *nonce = [NACLNonce nonce];

NSData *encryptedData;
encryptedData = [plainText encryptedDataUsingPrivateKey:privateKey nonce:nonce];

Decryption

plainText = [encryptedData decryptedDataUsingPrivateKey:privateKey nonce:&nonce];

Compatibility

The methods that perform private-key encryption also pack the nonce data at the beginning of the encrypted data object. The methods that perform private-key decryption without an explicit nonce argument expect nonce data to be packed at the beginning of the receiver. The methods that perform private-key decryption with an explicit nonce argument expect nonce data to not be packed at the beginning of the receiver. This behavior is provided as a convenience so you don't have to maintain the nonce. Keep in mind that if you consume encrypted data on another platform (or any library other than SodiumObjc), you should remove the nonce.

NSData *encryptedData;
encryptedData = [[plainText encryptedDataUsingPrivateKey:privateKey
                                                   nonce:nonce] dataWithoutNonce];

NSMutableURLRequest *request = ...
request.HTTPBody = encryptedData;

Signatures

Both NSString and NSData have been augmented with signing methods via the NSString+Nacl and NSData+NACL categories.

Signing

NSString *plainText = @"I am about to get encrypted.";
NACLSigningKeyPair *signingKeyPair = [NACLSigningKeyPair keyPair];
NACLNonce *nonce = [NACLNonce nonce];

NSData *signedData;
signedData = [plainText signedDataUsingPrivateKey:signingKeyPair.privateKey];

Verifying

NSString *verifiedText;
verifiedText = [signedData verifiedTextUsingPublicKey:signingKeyPair.publicKeyPair];

Building

Building libsodium consists of the following steps:

  • Fetch the contents of the libsodium submodule
  • Building libsodium for all involved architectures
  • Copying the built archives and headers to the correct location

The steps that I use to do this are:

git submodule update --init --recursive
cd libsodium-darwin-build
make clean all
cp libsodium-ios.a ../lib/ios/
cp libsodium-osx.a ../lib/osx/
cp -R build/iPhoneOS-arm64/include ../lib/ios/
cp -R build/MacOSX-x86_64/include ../lib/osx/

sodiumobjc's People

Contributors

nataliejameson avatar

Stargazers

Idraki Muhamad avatar Leyteris avatar  avatar Fiodar Morau avatar Oleg Bondar avatar Minlison avatar  avatar Gene avatar Ryan Rounkles avatar Jeff Youel avatar Steve Kwok avatar Hagen Hübel  avatar Anthony Headley avatar Ali Can Batur avatar  avatar tz ✨ avatar Chris Ballinger avatar Andy avatar Ilter Cengiz avatar Marcin Krzyzanowski avatar

Watchers

Noah Seger avatar Damian Carrillo avatar Chris Chang avatar Chris Ballinger avatar Guy Hoozdis avatar Stuart Prillaman avatar James Cloos avatar Cameron Hotchkies avatar Todd Smith avatar  avatar Minlison avatar  avatar

sodiumobjc's Issues

Create a pod

Hi,
first of all, thanks for this work. I was wondering whether you would be able to create a Pod (CocoaPods, see http://cocoapods.org/) for this project, so that it would be easier to integrate it with Objective-C projects just by specifying "pod 'SodiumObjc' ". I would like to use your code rather than https://github.com/gabriel/NAChloride, as they don't support asymmetric encryption as you do. It would be nice if you could provide the same easy way of integrating your project, though!
I don't have experience with this but I am happy to help, http://guides.cocoapods.org/making/making-a-cocoapod.html seems to be rather straight-forward.

Thanks in advance,
R

Is this library still maintained?

Hi @tabbedout-admin, I'm currently trying to tidy up the bindings linked on the libsodium website. If this library is still maintained, then please let me know; otherwise, the link to this library will likely be removed from the bindings page to help users find up to date and maintained bindings.

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.