Giter Club home page Giter Club logo

asymmetriccrypto's Introduction

AsymmetricCryptoManager

AsymmetricCryptoManager is a Swift implementation of an asymmetric cryptography manager to facilitate the use of asymmetric cryptographic operations in Swift. Included is a sample view controller for testing purposes.

Usage

AsymmetricCryptoManager follows the Singleton pattern, thus it must be accessed by means of the sharedInstance variable.

Generating a key pair

AsymmetricCryptoManager.sharedInstance.createSecureKeyPair({ (success, error) -> Void in
  if success {
    // start using the key pair.
  } else { 
    // handle the error
  }
})

Encryption:

AsymmetricCryptoManager.sharedInstance.encryptMessageWithPublicKey(clearText) { (success, data, error) -> Void in
  if success {
    let b64encoded = data!.base64EncodedStringWithOptions([])
    // transmit b64encoded encrypted string.
  } else { 
    // handle the error ...
  }
}

Decryption:

AsymmetricCryptoManager.sharedInstance.decryptMessageWithPrivateKey(encryptedData) { (success, result, error) -> Void in
  if success {
    // manage the resulting string.  
  } else {
    // manage the error
  }

Sign a message:

AsymmetricCryptoManager.sharedInstance.signMessageWithPrivateKey(clearText) { (success, data, error) -> Void in
  if success {
    let b64encoded = data!.base64EncodedStringWithOptions([])
  } else {
    // manage the error
  }
}

Verify the signature:

AsymmetricCryptoManager.sharedInstance.verifySignaturePublicKey(rawData, signatureData: signatureData) { (success, error) -> Void in
  if success {
    // verification was successful
  } else {
    // verification failed.
  }
}

LICENSE

The MIT License (MIT) Copyright (c) 2015 Ignacio Nieto Carvajal (http://digitalleaves.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

asymmetriccrypto's People

Contributors

digitalleaves 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

Watchers

 avatar  avatar  avatar  avatar

asymmetriccrypto's Issues

Can getPublicKeyData be made public again?

Hello,

I just upgraded to Swift 3 and also upgraded AssymetricCrypto. However, I am using getPublicKeyData which is now fileprivate so my code will not build. I can easily fix this by simply removing fileprivate, but I wanted to know if there is another way to get the public key data that I should be using. What I am currently doing:

AsymmetricCryptoManager.sharedInstance.createSecureKeyPair({ (success, error) in
   if success {
      let cryptoImportExportManager = CryptoExportImportManager()
      let publicKeyData = AsymmetricCryptoManager.sharedInstance.getPublicKeyData()
      publicKeyPem = cryptoImportExportManager.exportRSAPublicKeyToPEM(publicKeyData!, keyType: kSecAttrKeyTypeRSA as String, keySize: 2048)
                    
   } else {
      Log.error?.message("Error creating key pair: \(error.debugDescription)")
}

Perhaps you can remove fileprivate, unless there is a better way to do the above?

Thanks.

Consider adding the LICENSE file

Hey Ignacio, I just stumbled upon your repo and find this to be a good wrapper for the Security framework. I noticed in your blog post that the license adopted for this code is the MIT license. Do you mind adding this to the repo for clarity? Cheers.

There's no way to use my own keys?

I wish to use my public key to decrypt a string but I can't find any way to do so.
The asymetric crypto uses a generator for the keys.

Is there any way to make it work with my keys?

Can i decrypt my Encrypted message from my Go using EncryptPKCS1v15

Currently, i'm trying to implement this library to generate public key in my iOS device, and save it in my database through API.

When i send this public key from this library, i modify publicKeyData using https://github.com/DigitalLeaves/CryptoExportImportManager

But, when i encrypt from my backend (GoLang), and i tried to decode the encrypted message from my backend with this code:

   let encryptedData = Data(base64Encoded: encryptedMessage, options: [])
    
    AsymmetricCryptoManager.sharedInstance.decryptMessageWithPrivateKey(encryptedData!) { (success, result, error) -> Void in
        if success {
            print("result: \(result)")
        } else {
            print("Error decoding base64 string: \(error)")
        }
    }

it got error decoding base64 string: Optional(com.myProjects.AsymmetricCryptoException.unableToDecrypt)

After several research, i found, Golang encrypt using EncryptPKCS1v15 (https://github.com/golang/go/blob/master/src/crypto/rsa/pkcs1v15.go)
which make the iOS app failed to decrypt it because it only has PKCS1.

What should i do to decrypt with PKCS1v15 padding ?

Unsafe warnings with Swift 5

Hello,

I just upgraded a project where we use AsymmetricCrypto to Swift 5 and we are now getting several warnings "withUnsafeMutableBytes is deprecated...", e.g.::

image

It would be great if you could handle this.

Thanks.

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.