A wrapper for Apple's Common Crypto library written in Swift.

Overview

IDZSwiftCommonCrypto

Carthage compatible Build Status Coverage Status

A Swift wrapper for Apple's CommonCrypto library.

IDZSwiftCommonCrypto works with both CocoaPods and Cathage. For more details on how to install it into your projects see INSTALL.md

If you are using CococaPods you must use pod cache clean IDZSwiftCommonCrypto --all after you upgrade Xcode. This is needed to avoid stale module maps being used from the CocoaPods cache. Removing your Podfile.lock and Pods directory is not sufficient.

IDZSwiftCommonCrypto provides the following classes:

  • Digest for calculating message digests,
  • HMAC for calculating Hash-based Message Authentication Codes,
  • Cryptor for encrypting and decrypting bounded buffers,
  • StreamCryptor for encrypting and decrypting streaming information, and
  • PBKDF for deriving key material from a password or passphrase.

Which Release to Use

Which version you use depends on which version of Xcode and Swift you are currently using. Please refer to the list below:

  • 0.7.4 -- Xcode 7.3.1, Swift 2.2
  • 0.8.0 -- Xcode 7.3.1, Swift 2.2, with additional APIs for CCMode
  • 0.8.3 -- Xcode 8.0, Swift 2.3
  • 0.9.x -- Xcode 8.0, Swift 3.0
  • 0.10.x -- Xcode 9.0, Swift 4.0
  • 0.11.x -- Xcode 10.0, Swift 4.2
  • 0.12.x -- Xcode 10.2, Swift 5.0
  • 0.13.x -- Xcode 11.0, Swift 5.1, iOS 13.0

Using Digest

To calculate a message digest you create an instance of Digest, call update one or more times with the data over which the digest is being calculated and finally call final to obtain the digest itself.

The update method can take a String

let  s = "The quick brown fox jumps over the lazy dog."
var md5s2 : Digest = Digest(algorithm:.MD5)
md5s2.update(s)
let digests2 = md5s2.final()

// According to Wikipedia this should be
// e4d909c290d0fb1ca068ffaddf22cbd0
hexStringFromArray(digests2)
assert(digests2 == arrayFromHexString("e4d909c290d0fb1ca068ffaddf22cbd0"))

or an array of UInt8 elements:

let b : [UInt8] = 
[0x54,0x68,0x65,0x20,0x71,0x75,0x69,0x63,
0x6b,0x20,0x62,0x72,0x6f,0x77,0x6e,0x20,
0x66,0x6f,0x78,0x2e]
var md5s1 : Digest = Digest(algorithm:.MD5)
md5s1.update(b)
let digests1 = md5s1.final()

If you only have a single buffer you can simply write

  var digests3 = Digest(algorithm: .md5).update(b)?.final() // digest is of type [UInt8]?

or

  var digests4 = Digest(algorithm: .md5).update(s)?.final() // digest is of type [UInt8]?

Supported Algorithms

The Digest class supports the following algorithms:

  • .md2
  • .md4
  • .md5
  • .sha1
  • .sha224
  • .sha256
  • .sha384
  • .sha512

Using HMAC

Calculating a keyed-Hash Message Authentication Code (HMAC) is very similar to calculating a message digest, except that the initialization routine now takes a key as well as an algorithm parameter.

var keys5 = arrayFrom(hexString: "0102030405060708090a0b0c0d0e0f10111213141516171819")
var datas5 : [UInt8] = Array(count:50, repeatedValue:0xcd)
var expecteds5 = arrayFrom(hexString: "4c9007f4026250c6bc8414f9bf50c86c2d7235da")
var hmacs5 = HMAC(algorithm:.sha1, key:keys5).update(datas5)?.final()

// RFC2202 says this should be 4c9007f4026250c6bc8414f9bf50c86c2d7235da
let expectedRFC2202 = arrayFrom(hexString: "4c9007f4026250c6bc8414f9bf50c86c2d7235da")
assert(hmacs5! == expectedRFC2202)

Supported Algorithms

  • .md5
  • .sha1
  • .sha224
  • .sha256
  • .sha384
  • .sha512

Using Cryptor

let algorithm = Cryptor.Algorithm.aes
var iv = try! Random.generateBytes(byteCount: algorithm.blockSize())
var key = arrayFrom(hexString: "2b7e151628aed2a6abf7158809cf4f3c")
var plainText = "The quick brown fox jumps over the lazy dog. The fox has more or less had it at this point."

var cryptor = Cryptor(operation:.encrypt, algorithm:algorithm, options:.PKCS7Padding, key:key, iv:iv)
var cipherText = cryptor.update(plainText)?.final()

cryptor = Cryptor(operation:.decrypt, algorithm:algorithm, options:.PKCS7Padding, key:key, iv:iv)
var decryptedPlainText = cryptor.update(cipherText!)?.final()
var decryptedString = String(bytes: decryptedPlainText!, encoding: .utf8)
decryptedString
assert(decryptedString == plainText)

Supported Algorithms

  • .AES
  • .DES
  • .TripleDES
  • .CAST
  • .RC2
  • .Blowfish

Using StreamCryptor

To encrypt a large file or a network stream use StreamCryptor. The StreamCryptor class does not accumulate the encrypted or decrypted data, instead each call to update produces an output buffer.

The example below shows how to use StreamCryptor to encrypt and decrypt an image file.

func crypt(sc : StreamCryptor,  inputStream: InputStream, outputStream: OutputStream, bufferSize: Int) -> (bytesRead: Int, bytesWritten: Int)
{
    var inputBuffer = Array<UInt8>(repeating:0, count:1024)
    var outputBuffer = Array<UInt8>(repeating:0, count:1024)


    var cryptedBytes : Int = 0
    var totalBytesWritten = 0
    var totalBytesRead = 0
    while inputStream.hasBytesAvailable
    {
        let bytesRead = inputStream.read(&inputBuffer, maxLength: inputBuffer.count)
        totalBytesRead += bytesRead
        let status = sc.update(bufferIn: inputBuffer, byteCountIn: bytesRead, bufferOut: &outputBuffer, byteCapacityOut: outputBuffer.count, byteCountOut: &cryptedBytes)
        assert(status == Status.success)
        if(cryptedBytes > 0)
        {
            let bytesWritten = outputStream.write(outputBuffer, maxLength: Int(cryptedBytes))
            assert(bytesWritten == Int(cryptedBytes))
            totalBytesWritten += bytesWritten
        }
    }
    let status = sc.final(bufferOut: &outputBuffer, byteCapacityOut: outputBuffer.count, byteCountOut: &cryptedBytes)    
    assert(status == Status.success)
    if(cryptedBytes > 0)
    {
        let bytesWritten = outputStream.write(outputBuffer, maxLength: Int(cryptedBytes))
        assert(bytesWritten == Int(cryptedBytes))
        totalBytesWritten += bytesWritten
    }
    return (totalBytesRead, totalBytesWritten)
}

let imagePath = Bundle.main.path(forResource: "Riscal", ofType:"jpg")!
let tmp = NSTemporaryDirectory() as NSString
let encryptedFilePath = "\(tmp)/Riscal.xjpgx"
var decryptedFilePath = "\(tmp)/RiscalDecrypted.jpg"

// Prepare the input and output streams for the encryption operation
guard let imageInputStream = InputStream(fileAtPath: imagePath) else {
    fatalError("Failed to initialize the image input stream.")
}
imageInputStream.open()
guard let  encryptedFileOutputStream = OutputStream(toFileAtPath: encryptedFilePath, append:false) else
{
    fatalError("Failed to open output stream.")
}
encryptedFileOutputStream.open()

// Generate a new, random initialization vector
let initializationVector = try! Random.generateBytes(byteCount: algorithm.blockSize())

// A common way to communicate the initialization vector is to write it at the beginning of the encrypted data.
let bytesWritten = encryptedFileOutputStream.write(initializationVector, maxLength: initializationVector.count)

// Now write the encrypted data
var sc = StreamCryptor(operation:.encrypt, algorithm:algorithm, options:.PKCS7Padding, key:key, iv:initializationVector)
guard  bytesWritten == initializationVector.count else
{
    fatalError("Failed to write initialization vector to encrypted output file.")
}
let outputResult = crypt(sc: sc, inputStream: imageInputStream, outputStream: encryptedFileOutputStream, bufferSize: 1024)
encryptedFileOutputStream.close()
outputResult

// Uncomment this line to verify that the file is encrypted
//var encryptedImage = NSImage(contentsOfFile:encryptedFile)

// Prepare the input and output streams for the decryption operation
guard let encryptedFileInputStream = InputStream(fileAtPath: encryptedFilePath) else
{
    fatalError("Failed to open the encrypted file for input.")
}
encryptedFileInputStream.open()
guard let decryptedFileOutputStream = OutputStream(toFileAtPath: decryptedFilePath, append:false) else {
    fatalError("Failed to open the file for the decrypted output file.")
}
decryptedFileOutputStream.open()

// Read back the initialization vector.
var readbackInitializationVector = Array<UInt8>(repeating: 0, count: algorithm.blockSize())
let bytesRead = encryptedFileInputStream.read(&readbackInitializationVector, maxLength: readbackInitializationVector.count)

// Uncomment this to verify that we did indeed read back the initialization vector.
//assert(readbackInitializationVector == initializationVector)

// Now use the read back initialization vector (along with the key) to
sc = StreamCryptor(operation:.decrypt, algorithm:algorithm, options:.PKCS7Padding, key:key, iv:readbackInitializationVector)
let inputResult = crypt(sc: sc, inputStream: encryptedFileInputStream, outputStream: decryptedFileOutputStream, bufferSize: 1024)

// Uncomment this to verify that decrypt operation consumed all the encrypted data
// and produced the correct number of bytes of plaintext output.
//assert(inputResult.bytesRead == outputResult.bytesWritten && inputResult.bytesWritten == outputResult.bytesRead)

var image = NSImage(named:"Riscal.jpg")
var decryptedImage = NSImage(contentsOfFile:decryptedFilePath)
decryptedImage

Using PBKDF

The PBKDF class provides a method of deriving keys from a user password. The following example derives a 20-byte key:

let keys6 = PBKDF.deriveKey("password", salt: "salt", prf: .SHA1, rounds: 1, derivedKeyLength: 20)
// RFC 6070 - Should derive 0c60c80f961f0e71f3a9b524af6012062fe037a6
let expectedRFC6070 = arrayFrom(hexString: "0c60c80f961f0e71f3a9b524af6012062fe037a6")
assert(keys6 == expectedRFC6070)

Supported Pseudo-Random Functions

  • .sha1
  • .sha224
  • .sha256
  • .sha384
  • .sha512
Comments
  • Building Error

    Building Error

    When I update XCode 8.1 and re-build my project I get errors:

    Header '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.0.sdk/usr/include/CommonCrypto//CommonCrypto.h' not found AND Could not build Objective-C module 'CommonCrypto'

    thank you for help

    opened by AllenEzailLai 18
  • cocoapods error

    cocoapods error

    hello xcode8
    pod --version 1.1.0.beta.2 pod install error: ..... Installing IDZSwiftCommonCrypto (0.7.3) ....... [!] /bin/bash -c set -e touch prepare_command.txt echo 'Running prepare_command' pwd echo Running GenerateCommonCryptoModule swift ./GenerateCommonCryptoModule.swift macosx . swift ./GenerateCommonCryptoModule.swift iphonesimulator . swift ./GenerateCommonCryptoModule.swift iphoneos . swift ./GenerateCommonCryptoModule.swift appletvsimulator . swift ./GenerateCommonCryptoModule.swift appletvos . swift ./GenerateCommonCryptoModule.swift watchsimulator . swift ./GenerateCommonCryptoModule.swift watchos .

    Running prepare_command /Users/gongxinying/Library/Caches/CocoaPods/Pods/Release/IDZSwiftCommonCrypto/0.7.3-f4271 Running GenerateCommonCryptoModule ./GenerateCommonCryptoModule.swift:55:1: error: '@noreturn' has been removed; functions that never return should have a return type of 'Never' instead @noreturn func reportError(message: String) { ^~~~~~~~~~ -> Never ./GenerateCommonCryptoModule.swift:73:31: error: instance member 'arguments' cannot be used on type 'Process' guard let sdk = SDK(rawValue: Process.arguments[1])?.rawValue else { reportError("SDK must be one of (SDK.all.map { $0.rawValue })") } ^~~~~~~ ~~~~~~~~~ ./GenerateCommonCryptoModule.swift:73:82: error: missing argument label 'message:' in call guard let sdk = SDK(rawValue: Process.arguments[1])?.rawValue else { reportError("SDK must be one of (SDK.all.map { $0.rawValue })") } ^ message: ./GenerateCommonCryptoModule.swift:17:22: error: 'NSPipe' has been renamed to 'Pipe' let outputPipe = NSPipe() ^~~~~~ Pipe ./GenerateCommonCryptoModule.swift:18:16: error: 'NSTask' has been renamed to 'Process' let task = NSTask() ^~~~~~ Process ./GenerateCommonCryptoModule.swift:33:12: error: 'NSFileManager' has been renamed to 'FileManager' return NSFileManager.defaultManager().fileExistsAtPath(filePath) ^~~~~~~~~~~~~ FileManager ./GenerateCommonCryptoModule.swift:38:13: error: 'NSFileManager' has been renamed to 'FileManager' try NSFileManager.defaultManager().createDirectoryAtPath(path, withIntermediateDirectories: true, attributes: nil) ^~~~~~~~~~~~~ FileManager ./GenerateCommonCryptoModule.swift:48:108: error: cannot call value of non-function type 'CharacterSet' return ((s as NSString).stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()) as String) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~

    ./GenerateCommonCryptoModule.swift:52:37: error: missing argument label 's:' in call return (s == nil) ? nil : (trim(s!) as String) ^ s: ./GenerateCommonCryptoModule.swift:89:4: error: instance member 'arguments' cannot be used on type 'Process' if Process.arguments.count > 2 { ^~~~~~~ ~~~~~~~~~ ./GenerateCommonCryptoModule.swift:97:19: error: missing argument label 'filePath:' in call if fileExists(moduleDirectory) { ^ filePath: ./GenerateCommonCryptoModule.swift:98:21: error: missing argument label 'message:' in call reportError("Module directory already exists at (moduleDirectory).") ^ message: ./GenerateCommonCryptoModule.swift:102:11: error: missing argument label 'path:' in call if !mkdir(moduleDirectory) { ^ path: ./GenerateCommonCryptoModule.swift:103:17: error: missing argument label 'message:' in call reportError("Failed to create module directory (moduleDirectory)") ^ message: ./GenerateCommonCryptoModule.swift:124:17: error: missing argument label 'message:' in call reportError("Failed to write module map file to (moduleMapPath)") ^ message:

    opened by AsTryE 13
  • Carthage Build fails for IDZSwiftCommonCrypto

    Carthage Build fails for IDZSwiftCommonCrypto

    Carthage is not getting build for IDZSwiftCommonCrypto. Following is the error i am getting.

    The following build commands failed: CompileSwift normal arm64 /Users/MyComputer/Documents/ - iOS/10 May/XXXXX/Carthage/Checkouts/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto/Utilities.swift CompileSwift normal arm64 /Users/MyComputer/Documents/ - iOS/10 May/XXXXX/Carthage/Checkouts/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto/KeyDerivation.swift CompileSwift normal arm64 /Users/MyComputer/Documents/ - iOS/10 May/XXXXX/Carthage/Checkouts/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto/Status.swift CompileSwift normal arm64 /Users/MyComputer/Documents/ - iOS/10 May/XXXXX/Carthage/Checkouts/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto/Crypto.swift CompileSwift normal arm64 /Users/MyComputer/Documents/ - iOS/10 May/XXXXX/Carthage/Checkouts/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto/Cryptor.swift CompileSwift normal arm64 /Users/MyComputer/Documents/ - iOS/10 May/XXXXX/Carthage/Checkouts/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto/StreamCryptor.swift CompileSwift normal arm64 /Users/MyComputer/Documents/ - iOS/10 May/XXXXX/Carthage/Checkouts/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto/Updateable.swift CompileSwift normal arm64 /Users/MyComputer/Documents/ - iOS/10 May/XXXXX/Carthage/Checkouts/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto/Random.swift CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler (9 failures) /Users/MyComputer/Documents/ - iOS/10 May/XXXXX/Carthage/Checkouts/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto/KeyDerivation.swift:10:8: error: no such module 'CommonCrypto' /Users/MyComputer/Documents/ - iOS/10 May/XXXXX/Carthage/Checkouts/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto/KeyDerivation.swift:10:8: error: no such module 'CommonCrypto' /Users/MyComputer/Documents/ - iOS/10 May/XXXXX/Carthage/Checkouts/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto/KeyDerivation.swift:10:8: error: no such module 'CommonCrypto' /Users/MyComputer/Documents/ - iOS/10 May/XXXXX/Carthage/Checkouts/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto/KeyDerivation.swift:10:8: error: no such module 'CommonCrypto' /Users/MyComputer/Documents/ - iOS/10 May/XXXXX/Carthage/Checkouts/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto/KeyDerivation.swift:10:8: error: no such module 'CommonCrypto' /Users/MyComputer/Documents/ - iOS/10 May/XXXXX/Carthage/Checkouts/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto/KeyDerivation.swift:10:8: error: no such module 'CommonCrypto' /Users/MyComputer/Documents/ - iOS/10 May/XXXXX/Carthage/Checkouts/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto/KeyDerivation.swift:10:8: error: no such module 'CommonCrypto' /Users/MyComputer/Documents/ - iOS/10 May/XXXXX/Carthage/Checkouts/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto/KeyDerivation.swift:10:8: error: no such module 'CommonCrypto' A shell task (/usr/bin/xcrun xcodebuild -workspace /Users/MyComputer/Documents/ - iOS/10 May/XXXXX/Carthage/Checkouts/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto.xcworkspace -scheme IDZSwiftCommonCrypto (Release) -configuration Release -sdk iphoneos 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: CompileSwift normal arm64 /Users/MyComputer/Documents/ - iOS/10 May/XXXXX/Carthage/Checkouts/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto/Utilities.swift CompileSwift normal arm64 /Users/MyComputer/Documents/ - iOS/10 May/XXXXX/Carthage/Checkouts/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto/KeyDerivation.swift CompileSwift normal arm64 /Users/MyComputer/Documents/ - iOS/10 May/XXXXX/Carthage/Checkouts/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto/Status.swift CompileSwift normal arm64 /Users/MyComputer/Documents/ - iOS/10 May/XXXXX/Carthage/Checkouts/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto/Crypto.swift CompileSwift normal arm64 /Users/MyComputer/Documents/ - iOS/10 May/XXXXX/Carthage/Checkouts/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto/Cryptor.swift CompileSwift normal arm64 /Users/MyComputer/Documents/ - iOS/10 May/XXXXX/Carthage/Checkouts/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto/StreamCryptor.swift CompileSwift normal arm64 /Users/MyComputer/Documents/ - iOS/10 May/XXXXX/Carthage/Checkouts/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto/Updateable.swift CompileSwift normal arm64 /Users/MyComputer/Documents/ - iOS/10 May/XXXXX/Carthage/Checkouts/IDZSwiftCommonCrypto/IDZSwiftCommonCrypto/Random.swift CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler (9 failures)

    Some body please help me

    question 
    opened by priyapy 13
  • DES Encryption and Decryption not working

    DES Encryption and Decryption not working

    I'm trying to use the DES encryption using ECB mode but it's not working. I validate it using the online encryption tool that works. I changed my keys and plain text to not display our own key and text and used a different pair. IDZSwiftCommonCrypto yields different results everytime I tap my Start button. Here's my code:

    import UIKit
    import IDZSwiftCommonCrypto
    
    class ViewController: UIViewController {
    
        @IBOutlet weak var keyTextField: UITextField! // key is thekey
        @IBOutlet weak var plainTextField: UITextField! // plain text is username123
        @IBOutlet weak var outputTextView: UITextView! // output should be b742acfaa07e3d05cf2dc9aaa0258fc2
        @IBOutlet weak var encryptionSegmentedControl: UISegmentedControl!
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            UIApplication.sharedApplication().statusBarStyle = .LightContent
        }
    
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
    
    
        @IBAction func startButtonTapped(sender: UIButton) {
            if encryptionSegmentedControl.selectedSegmentIndex == 0 {
                let hexKey = arrayFromHexString(convertToHexFromString(keyTextField.text!))
                let encryptedBytesArray = Cryptor(operation:.Encrypt, algorithm:.DES, options:.ECBMode, key:hexKey, iv:[UInt8]()).update(arrayFromHexString(convertToHexFromString(plainTextField.text!)))?.final()
    
                outputTextView.text = hexStringFromArray(encryptedBytesArray!)
            } else {
                let hexKey = arrayFromHexString(convertToHexFromString(keyTextField.text!))
                let decryptedBytesArray = Cryptor(operation:.Decrypt, algorithm:.DES, options:.ECBMode, key:hexKey, iv:[UInt8]()).update(plainTextField.text!)?.final()
    
                outputTextView.text = hexStringFromArray(decryptedBytesArray!)
            }
        }
    
        // MARK: - Custom
    
        @IBAction func dismissKeyboard() {
            self.view.endEditing(true)
        }
    
        func convertToHexFromString(rawString: String) -> String! {
            var hexString = "\(rawString.dataUsingEncoding(NSUTF8StringEncoding)!)"
            hexString = hexString.stringByReplacingOccurrencesOfString(" ", withString: "").stringByTrimmingCharactersInSet(NSCharacterSet.symbolCharacterSet())
    
            print("Formatted hex string: \(hexString)")
    
            return hexString
        }
    
        func encryptUsingText(hexText: String, hexKey: [UInt8]) -> String! {
            let cryptor = Cryptor(operation:.Encrypt, algorithm:.DES, options:.ECBMode, key:hexKey, iv:[UInt8]())
            let cipherText = cryptor.update(hexText)?.final()
    
            print("Bytes array: \(cipherText!)")
    
            return String(bytes: cipherText!, encoding: NSUTF8StringEncoding)
        }
    
        func decryptUsingText(rawText: String, hexKey: [UInt8]) -> String! {
            let cryptor = Cryptor(operation:.Decrypt, algorithm:.DES, options:.None, key:hexKey, iv:[UInt8]())
            let decryptedCipherText = cryptor.update(rawText)?.final()
    
            print("Bytes array: \(decryptedCipherText!)")
    
            return String(bytes: decryptedCipherText!, encoding: NSUTF8StringEncoding)
        }
    
    }
    
    opened by jaytrixz 13
  • Use salt as an array of bytes instead of String

    Use salt as an array of bytes instead of String

    Use salt as an array of bytes instead of String. Also added arrayFromString to ease use of existing code samples.

    Note: it's my first pull request. Sorry if I'm messing something.

    opened by andredsp 10
  • Problem when install pod

    Problem when install pod

    I have problem like this on xcode 10.2 & swift 5, using 0.10.0 version because other library requiered that

    `[!] /bin/bash -c set -e touch prepare_command.txt echo 'Running prepare_command' pwd echo Running GenerateCommonCryptoModule

    This was needed to ensure the correct Swift interpreter was

    used in Xcode 8. Leaving it here, commented out, in case similar

    issues occur when migrating to Swift 4.0.

    #TC="--toolchain com.apple.dt.toolchain.Swift_2_3" SWIFT="xcrun $TC swift" $SWIFT ./GenerateCommonCryptoModule.swift macosx . $SWIFT ./GenerateCommonCryptoModule.swift iphonesimulator . $SWIFT ./GenerateCommonCryptoModule.swift iphoneos . $SWIFT ./GenerateCommonCryptoModule.swift appletvsimulator . $SWIFT ./GenerateCommonCryptoModule.swift appletvos . $SWIFT ./GenerateCommonCryptoModule.swift watchsimulator . $SWIFT ./GenerateCommonCryptoModule.swift watchos .

    Running prepare_command /Users/khairulrijal/Library/Caches/CocoaPods/Pods/Release/IDZSwiftCommonCrypto/0.10.0-4eef2 Running GenerateCommonCryptoModule ./GenerateCommonCryptoModule.swift:15:34: error: 'characters' is unavailable: Please use String directly let args: [String] = command.characters.split { $0 == " " }.map(String.init) ^~~~~~~~~~ Swift.String:5:16: note: 'characters' was obsoleted in Swift 5.0 public var characters: String { get set } ^ `

    awaiting info 
    opened by KhairulRijl 9
  • Missing required module 'CommonCrypto'

    Missing required module 'CommonCrypto'

    I'm getting this error when building on a new machine

    AESCryptor.swift:10:8: Missing required module 'CommonCrypto'

    Is there something I must do before using this framework ?

    opened by mateo666 9
  • Got this error when I try to install.

    Got this error when I try to install.

    [!] /bin/bash -c set -e touch prepare_command.txt echo 'Running prepare_command' pwd echo Running GenerateCommonCryptoModule

    This was needed to ensure the correct Swift interpreter was

    used in Xcode 8. Leaving it here, commented out, in case similar

    issues occur when migrating to Swift 4.0.

    #TC="--toolchain com.apple.dt.toolchain.Swift_2_3" SWIFT="xcrun $TC swift" $SWIFT ./GenerateCommonCryptoModule.swift macosx . $SWIFT ./GenerateCommonCryptoModule.swift iphonesimulator . $SWIFT ./GenerateCommonCryptoModule.swift iphoneos . $SWIFT ./GenerateCommonCryptoModule.swift appletvsimulator . $SWIFT ./GenerateCommonCryptoModule.swift appletvos . $SWIFT ./GenerateCommonCryptoModule.swift watchsimulator . $SWIFT ./GenerateCommonCryptoModule.swift watchos .

    Running prepare_command /Users/abhishek/Library/Caches/CocoaPods/Pods/Release/IDZSwiftCommonCrypto/0.10.0-4eef2 Running GenerateCommonCryptoModule SDK: macosx SDK Version: 10.13 SDK Path: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk Successfully created module ./Frameworks/macosx/CommonCrypto.framework/module.map ERROR: ERROR: Failed to determine SDK version for iphonesimulator ./GenerateCommonCryptoModule.swift:15:34: warning: 'characters' is deprecated: Please use String or Substring directly let args: [String] = command.characters.split { $0 == " " }.map(String.init) ^ ./GenerateCommonCryptoModule.swift:15:34: warning: 'characters' is deprecated: Please use String or Substring directly let args: [String] = command.characters.split { $0 == " " }.map(String.init) ^ xcrun: error: SDK "iphonesimulator" cannot be located xcrun: error: SDK "iphonesimulator" cannot be located xcrun: error: unable to lookup item 'SDKVersion' in SDK 'iphonesimulator'

    opened by Abhishek2611 9
  • First few characters in AES decrypted text are strange

    First few characters in AES decrypted text are strange

    Hi IDZ,

    I'm getting a few strange characters at the beginning of the decrypted text using the following extensions on String, based on your example code. The [UInt8] data passed to decrypt is coming from a stored file (of the encrypted data). After the first few characters, the rest of the decrypted text is perfect.

    Any help would be greatly appreciated! Thank you.

    public extension String {
    
    	func encryptAsData(key: [UInt8]) -> [UInt8]? {
    				
    		let cryptor = Cryptor(operation:.encrypt, algorithm: .aes, options: .PKCS7Padding, key: key, iv: Array<UInt8>())
    		
    		return cryptor.update(string: self)?.final()
    	}
    	
    	static func decrypt(data: [UInt8], key: [UInt8]) -> String? {
    		
    		let cryptor = Cryptor(operation: .decrypt, algorithm: .aes, options: .PKCS7Padding, key: key, iv: Array<UInt8>())
    		
    		if let decryptedData = cryptor.update(byteArray: data)?.final() {
    			
    			return decryptedData.reduce("") { $0 + String(UnicodeScalar($1)) }
    		}
    		
    		return nil
    	}
    }
    
    bug 
    opened by chessboy 8
  • Installing IDZSwiftCommonCrypto 0.8.1 using Cocoapods 1.1.0 RC 2

    Installing IDZSwiftCommonCrypto 0.8.1 using Cocoapods 1.1.0 RC 2

    I'm having this error messages when installing my pods. All my other dependencies are working fine except for IDZSwiftCommonCrypto. This was triggered by updating my pod file. Any idea where I'm having issues?

    -> Installing IDZSwiftCommonCrypto (0.8.1)

    Git download Git download $ /usr/bin/git clone https://github.com/iosdevzone/IDZSwiftCommonCrypto.git /var/folders/gh/dypd9prs2jd7cg7_d59fqqyc0000gn/T/d20161003-29724-z4a2jx --template= --single-branch --depth 1 --branch 0.8.1 Cloning into '/var/folders/gh/dypd9prs2jd7cg7_d59fqqyc0000gn/T/d20161003-29724-z4a2jx'... Note: checking out 'af20cf990069900d0ec96d82a4531bec57563637'.

     You are in 'detached HEAD' state. You can look around, make experimental
     changes and commit them, and you can discard any commits you make in this
     state without impacting any branches by performing another checkout.
    
     If you want to create a new branch to retain commits you create, you may
     do so (now or later) by using -b with the checkout command again. Example:
    
       git checkout -b <new-branch-name>
    

    Running prepare command $ /bin/bash -c set -e touch prepare_command.txt echo 'Running prepare_command' pwd echo Running GenerateCommonCryptoModule swift ./GenerateCommonCryptoModule.swift macosx . swift ./GenerateCommonCryptoModule.swift iphonesimulator . swift ./GenerateCommonCryptoModule.swift iphoneos . swift ./GenerateCommonCryptoModule.swift appletvsimulator . swift ./GenerateCommonCryptoModule.swift appletvos . swift ./GenerateCommonCryptoModule.swift watchsimulator . swift ./GenerateCommonCryptoModule.swift watchos . Running prepare_command /Users/administrator/Library/Caches/CocoaPods/Pods/Release/IDZSwiftCommonCrypto/0.8.1-0fe7e Running GenerateCommonCryptoModule ./GenerateCommonCryptoModule.swift:55:1: error: '@noreturn' has been removed; functions that never return should have a return type of 'Never' instead @noreturn func reportError(message: String) { ^~~~~~~~~~ -> Never ./GenerateCommonCryptoModule.swift:73:31: error: instance member 'arguments' cannot be used on type 'Process' guard let sdk = SDK(rawValue: Process.arguments[1])?.rawValue else { reportError("SDK must be one of (SDK.all.map { $0.rawValue })") } ^~~~~~~ ~~~~~~~~~ ./GenerateCommonCryptoModule.swift:73:82: error: missing argument label 'message:' in call guard let sdk = SDK(rawValue: Process.arguments[1])?.rawValue else { reportError("SDK must be one of (SDK.all.map { $0.rawValue })") } ^ message: ./GenerateCommonCryptoModule.swift:17:22: error: 'NSPipe' has been renamed to 'Pipe' let outputPipe = NSPipe() ^~~~~~ Pipe ./GenerateCommonCryptoModule.swift:18:16: error: 'NSTask' has been renamed to 'Process' let task = NSTask() ^~~~~~ Process ./GenerateCommonCryptoModule.swift:33:12: error: 'NSFileManager' has been renamed to 'FileManager' return NSFileManager.defaultManager().fileExistsAtPath(filePath) ^~~~~~~~~~~~~ FileManager ./GenerateCommonCryptoModule.swift:38:13: error: 'NSFileManager' has been renamed to 'FileManager' try NSFileManager.defaultManager().createDirectoryAtPath(path, withIntermediateDirectories: true, attributes: nil) ^~~~~~~~~~~~~ FileManager ./GenerateCommonCryptoModule.swift:48:108: error: cannot call value of non-function type 'CharacterSet' return ((s as NSString).stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()) as String) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~

    ./GenerateCommonCryptoModule.swift:52:37: error: missing argument label 's:' in call return (s == nil) ? nil : (trim(s!) as String) ^ s: ./GenerateCommonCryptoModule.swift:89:4: error: instance member 'arguments' cannot be used on type 'Process' if Process.arguments.count > 2 { ^~~~~~~ ~~~~~~~~~ ./GenerateCommonCryptoModule.swift:97:19: error: missing argument label 'filePath:' in call if fileExists(moduleDirectory) { ^ filePath: ./GenerateCommonCryptoModule.swift:98:21: error: missing argument label 'message:' in call reportError("Module directory already exists at (moduleDirectory).") ^ message: ./GenerateCommonCryptoModule.swift:102:11: error: missing argument label 'path:' in call if !mkdir(moduleDirectory) { ^ path: ./GenerateCommonCryptoModule.swift:103:17: error: missing argument label 'message:' in call reportError("Failed to create module directory (moduleDirectory)") ^ message: ./GenerateCommonCryptoModule.swift:124:17: error: missing argument label 'message:' in call reportError("Failed to write module map file to (moduleMapPath)") ^ message: [!] /bin/bash -c set -e touch prepare_command.txt echo 'Running prepare_command' pwd echo Running GenerateCommonCryptoModule swift ./GenerateCommonCryptoModule.swift macosx . swift ./GenerateCommonCryptoModule.swift iphonesimulator . swift ./GenerateCommonCryptoModule.swift iphoneos . swift ./GenerateCommonCryptoModule.swift appletvsimulator . swift ./GenerateCommonCryptoModule.swift appletvos . swift ./GenerateCommonCryptoModule.swift watchsimulator . swift ./GenerateCommonCryptoModule.swift watchos .

    Running prepare_command /Users/administrator/Library/Caches/CocoaPods/Pods/Release/IDZSwiftCommonCrypto/0.8.1-0fe7e Running GenerateCommonCryptoModule ./GenerateCommonCryptoModule.swift:55:1: error: '@noreturn' has been removed; functions that never return should have a return type of 'Never' instead @noreturn func reportError(message: String) { ^~~~~~~~~~ -> Never ./GenerateCommonCryptoModule.swift:73:31: error: instance member 'arguments' cannot be used on type 'Process' guard let sdk = SDK(rawValue: Process.arguments[1])?.rawValue else { reportError("SDK must be one of (SDK.all.map { $0.rawValue })") } ^~~~~~~ ~~~~~~~~~ ./GenerateCommonCryptoModule.swift:73:82: error: missing argument label 'message:' in call guard let sdk = SDK(rawValue: Process.arguments[1])?.rawValue else { reportError("SDK must be one of (SDK.all.map { $0.rawValue })") } ^ message: ./GenerateCommonCryptoModule.swift:17:22: error: 'NSPipe' has been renamed to 'Pipe' let outputPipe = NSPipe() ^~~~~~ Pipe ./GenerateCommonCryptoModule.swift:18:16: error: 'NSTask' has been renamed to 'Process' let task = NSTask() ^~~~~~ Process ./GenerateCommonCryptoModule.swift:33:12: error: 'NSFileManager' has been renamed to 'FileManager' return NSFileManager.defaultManager().fileExistsAtPath(filePath) ^~~~~~~~~~~~~ FileManager ./GenerateCommonCryptoModule.swift:38:13: error: 'NSFileManager' has been renamed to 'FileManager' try NSFileManager.defaultManager().createDirectoryAtPath(path, withIntermediateDirectories: true, attributes: nil) ^~~~~~~~~~~~~ FileManager ./GenerateCommonCryptoModule.swift:48:108: error: cannot call value of non-function type 'CharacterSet' return ((s as NSString).stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()) as String) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~

    ./GenerateCommonCryptoModule.swift:52:37: error: missing argument label 's:' in call return (s == nil) ? nil : (trim(s!) as String) ^ s: ./GenerateCommonCryptoModule.swift:89:4: error: instance member 'arguments' cannot be used on type 'Process' if Process.arguments.count > 2 { ^~~~~~~ ~~~~~~~~~ ./GenerateCommonCryptoModule.swift:97:19: error: missing argument label 'filePath:' in call if fileExists(moduleDirectory) { ^ filePath: ./GenerateCommonCryptoModule.swift:98:21: error: missing argument label 'message:' in call reportError("Module directory already exists at (moduleDirectory).") ^ message: ./GenerateCommonCryptoModule.swift:102:11: error: missing argument label 'path:' in call if !mkdir(moduleDirectory) { ^ path: ./GenerateCommonCryptoModule.swift:103:17: error: missing argument label 'message:' in call reportError("Failed to create module directory (moduleDirectory)") ^ message: ./GenerateCommonCryptoModule.swift:124:17: error: missing argument label 'message:' in call reportError("Failed to write module map file to (moduleMapPath)") ^ message:

    /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/executable.rb:69:in execute_command' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/executable.rb:27:inblock in executable' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/installer/pod_source_preparer.rb:66:in block (2 levels) in run_prepare_command' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/installer/pod_source_preparer.rb:60:inchdir' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/installer/pod_source_preparer.rb:60:in block in run_prepare_command' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/user_interface.rb:64:insection' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/installer/pod_source_preparer.rb:59:in run_prepare_command' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/installer/pod_source_preparer.rb:37:inprepare!' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/downloader/cache.rb:202:in copy_and_clean' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/downloader/cache.rb:159:inblock (2 levels) in uncached_pod' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/downloader/cache.rb:157:in each' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/downloader/cache.rb:157:inblock in uncached_pod' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/downloader/cache.rb:181:in call' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/downloader/cache.rb:181:inin_tmpdir' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/downloader/cache.rb:153:in uncached_pod' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/downloader/cache.rb:33:indownload_pod' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/downloader.rb:42:in download' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/installer/pod_source_installer.rb:120:indownload_source' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/installer/pod_source_installer.rb:60:in install!' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/installer.rb:355:ininstall_source_of_pod' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/installer.rb:322:in block (2 levels) in install_pod_sources' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/user_interface.rb:85:intitled_section' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/installer.rb:321:in block in install_pod_sources' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/installer.rb:313:ineach' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/installer.rb:313:in install_pod_sources' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/installer.rb:159:inblock in download_dependencies' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/user_interface.rb:64:in section' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/installer.rb:157:indownload_dependencies' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/installer.rb:111:in install!' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/command/install.rb:37:inrun' /Library/Ruby/Gems/2.0.0/gems/claide-1.0.0/lib/claide/command.rb:334:in run' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/command.rb:50:inrun' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/bin/pod:55:in <top (required)>' /usr/local/bin/pod:23:inload' /usr/local/bin/pod:23:in `

    '

    opened by jaytrixz 8
  • Xcode 11 support

    Xcode 11 support

    When compiling with Xcode 11, we get these compiler errors:

    • Use of unresolved identifier 'kCCModeF8'
    • Use of unresolved identifier 'kCCModeLRW'
    • Use of unresolved identifier 'kCCModeXTS'
    opened by rjchatfield 7
  • Bump nokogiri from 1.10.8 to 1.13.9

    Bump nokogiri from 1.10.8 to 1.13.9

    Bumps nokogiri from 1.10.8 to 1.13.9.

    Release notes

    Sourced from nokogiri's releases.

    1.13.9 / 2022-10-18

    Security

    Dependencies

    • [CRuby] Vendored libxml2 is updated to v2.10.3 from v2.9.14.
    • [CRuby] Vendored libxslt is updated to v1.1.37 from v1.1.35.
    • [CRuby] Vendored zlib is updated from 1.2.12 to 1.2.13. (See LICENSE-DEPENDENCIES.md for details on which packages redistribute this library.)

    Fixed

    • [CRuby] Nokogiri::XML::Namespace objects, when compacted, update their internal struct's reference to the Ruby object wrapper. Previously, with GC compaction enabled, a segmentation fault was possible after compaction was triggered. [#2658] (Thanks, @​eightbitraptor and @​peterzhu2118!)
    • [CRuby] Document#remove_namespaces! now defers freeing the underlying xmlNs struct until the Document is GCed. Previously, maintaining a reference to a Namespace object that was removed in this way could lead to a segfault. [#2658]

    sha256 checksums:

    9b69829561d30c4461ea803baeaf3460e8b145cff7a26ce397119577a4083a02  nokogiri-1.13.9-aarch64-linux.gem
    e76ebb4b7b2e02c72b2d1541289f8b0679fb5984867cf199d89b8ef485764956  nokogiri-1.13.9-arm64-darwin.gem
    15bae7d08bddeaa898d8e3f558723300137c26a2dc2632a1f89c8574c4467165  nokogiri-1.13.9-java.gem
    f6a1dbc7229184357f3129503530af73cc59ceba4932c700a458a561edbe04b9  nokogiri-1.13.9-x64-mingw-ucrt.gem
    36d935d799baa4dc488024f71881ff0bc8b172cecdfc54781169c40ec02cbdb3  nokogiri-1.13.9-x64-mingw32.gem
    ebaf82aa9a11b8fafb67873d19ee48efb565040f04c898cdce8ca0cd53ff1a12  nokogiri-1.13.9-x86-linux.gem
    11789a2a11b28bc028ee111f23311461104d8c4468d5b901ab7536b282504154  nokogiri-1.13.9-x86-mingw32.gem
    01830e1646803ff91c0fe94bc768ff40082c6de8cfa563dafd01b3f7d5f9d795  nokogiri-1.13.9-x86_64-darwin.gem
    8e93b8adec22958013799c8690d81c2cdf8a90b6f6e8150ab22e11895844d781  nokogiri-1.13.9-x86_64-linux.gem
    96f37c1baf0234d3ae54c2c89aef7220d4a8a1b03d2675ff7723565b0a095531  nokogiri-1.13.9.gem
    

    1.13.8 / 2022-07-23

    Deprecated

    • XML::Reader#attribute_nodes is deprecated due to incompatibility between libxml2's xmlReader memory semantics and Ruby's garbage collector. Although this method continues to exist for backwards compatibility, it is unsafe to call and may segfault. This method will be removed in a future version of Nokogiri, and callers should use #attribute_hash instead. [#2598]

    Improvements

    • XML::Reader#attribute_hash is a new method to safely retrieve the attributes of a node from XML::Reader. [#2598, #2599]

    Fixed

    ... (truncated)

    Changelog

    Sourced from nokogiri's changelog.

    1.13.9 / 2022-10-18

    Security

    Dependencies

    • [CRuby] Vendored libxml2 is updated to v2.10.3 from v2.9.14.
    • [CRuby] Vendored libxslt is updated to v1.1.37 from v1.1.35.
    • [CRuby] Vendored zlib is updated from 1.2.12 to 1.2.13. (See LICENSE-DEPENDENCIES.md for details on which packages redistribute this library.)

    Fixed

    • [CRuby] Nokogiri::XML::Namespace objects, when compacted, update their internal struct's reference to the Ruby object wrapper. Previously, with GC compaction enabled, a segmentation fault was possible after compaction was triggered. [#2658] (Thanks, @​eightbitraptor and @​peterzhu2118!)
    • [CRuby] Document#remove_namespaces! now defers freeing the underlying xmlNs struct until the Document is GCed. Previously, maintaining a reference to a Namespace object that was removed in this way could lead to a segfault. [#2658]

    1.13.8 / 2022-07-23

    Deprecated

    • XML::Reader#attribute_nodes is deprecated due to incompatibility between libxml2's xmlReader memory semantics and Ruby's garbage collector. Although this method continues to exist for backwards compatibility, it is unsafe to call and may segfault. This method will be removed in a future version of Nokogiri, and callers should use #attribute_hash instead. [#2598]

    Improvements

    • XML::Reader#attribute_hash is a new method to safely retrieve the attributes of a node from XML::Reader. [#2598, #2599]

    Fixed

    • [CRuby] Calling XML::Reader#attributes is now safe to call. In Nokogiri <= 1.13.7 this method may segfault. [#2598, #2599]

    1.13.7 / 2022-07-12

    Fixed

    XML::Node objects, when compacted, update their internal struct's reference to the Ruby object wrapper. Previously, with GC compaction enabled, a segmentation fault was possible after compaction was triggered. [#2578] (Thanks, @​eightbitraptor!)

    1.13.6 / 2022-05-08

    Security

    • [CRuby] Address CVE-2022-29181, improper handling of unexpected data types, related to untrusted inputs to the SAX parsers. See GHSA-xh29-r2w5-wx8m for more information.

    ... (truncated)

    Commits
    • 897759c version bump to v1.13.9
    • aeb1ac3 doc: update CHANGELOG
    • c663e49 Merge pull request #2671 from sparklemotion/flavorjones-update-zlib-1.2.13_v1...
    • 212e07d ext: hack to cross-compile zlib v1.2.13 on darwin
    • 76dbc8c dep: update zlib to v1.2.13
    • 24e3a9c doc: update CHANGELOG
    • 4db3b4d Merge pull request #2668 from sparklemotion/flavorjones-namespace-scopes-comp...
    • 73d73d6 fix: Document#remove_namespaces! use-after-free bug
    • 5f58b34 fix: namespace nodes behave properly when compacted
    • b08a858 test: repro namespace_scopes compaction issue
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Bump tzinfo from 1.2.5 to 1.2.10

    Bump tzinfo from 1.2.5 to 1.2.10

    Bumps tzinfo from 1.2.5 to 1.2.10.

    Release notes

    Sourced from tzinfo's releases.

    v1.2.10

    TZInfo v1.2.10 on RubyGems.org

    v1.2.9

    • Fixed an incorrect InvalidTimezoneIdentifier exception raised when loading a zoneinfo file that includes rules specifying an additional transition to the final defined offset (for example, Africa/Casablanca in version 2018e of the Time Zone Database). #123.

    TZInfo v1.2.9 on RubyGems.org

    v1.2.8

    • Added support for handling "slim" format zoneinfo files that are produced by default by zic version 2020b and later. The POSIX-style TZ string is now used calculate DST transition times after the final defined transition in the file. The 64-bit section is now always used regardless of whether Time has support for 64-bit times. #120.
    • Rubinius is no longer supported.

    TZInfo v1.2.8 on RubyGems.org

    v1.2.7

    • Fixed 'wrong number of arguments' errors when running on JRuby 9.0. #114.
    • Fixed warnings when running on Ruby 2.8. #112.

    TZInfo v1.2.7 on RubyGems.org

    v1.2.6

    • Timezone#strftime('%s', time) will now return the correct number of seconds since the epoch. #91.
    • Removed the unused TZInfo::RubyDataSource::REQUIRE_PATH constant.
    • Fixed "SecurityError: Insecure operation - require" exceptions when loading data with recent Ruby releases in safe mode.
    • Fixed warnings when running on Ruby 2.7. #106 and #111.

    TZInfo v1.2.6 on RubyGems.org

    Changelog

    Sourced from tzinfo's changelog.

    Version 1.2.10 - 19-Jul-2022

    Version 1.2.9 - 16-Dec-2020

    • Fixed an incorrect InvalidTimezoneIdentifier exception raised when loading a zoneinfo file that includes rules specifying an additional transition to the final defined offset (for example, Africa/Casablanca in version 2018e of the Time Zone Database). #123.

    Version 1.2.8 - 8-Nov-2020

    • Added support for handling "slim" format zoneinfo files that are produced by default by zic version 2020b and later. The POSIX-style TZ string is now used calculate DST transition times after the final defined transition in the file. The 64-bit section is now always used regardless of whether Time has support for 64-bit times. #120.
    • Rubinius is no longer supported.

    Version 1.2.7 - 2-Apr-2020

    • Fixed 'wrong number of arguments' errors when running on JRuby 9.0. #114.
    • Fixed warnings when running on Ruby 2.8. #112.

    Version 1.2.6 - 24-Dec-2019

    • Timezone#strftime('%s', time) will now return the correct number of seconds since the epoch. #91.
    • Removed the unused TZInfo::RubyDataSource::REQUIRE_PATH constant.
    • Fixed "SecurityError: Insecure operation - require" exceptions when loading data with recent Ruby releases in safe mode.
    • Fixed warnings when running on Ruby 2.7. #106 and #111.
    Commits
    • 0814dcd Fix the release date.
    • fd05e2a Preparing v1.2.10.
    • b98c32e Merge branch 'fix-directory-traversal-1.2' into 1.2
    • ac3ee68 Remove unnecessary escaping of + within regex character classes.
    • 9d49bf9 Fix relative path loading tests.
    • 394c381 Remove private_constant for consistency and compatibility.
    • 5e9f990 Exclude Arch Linux's SECURITY file from the time zone index.
    • 17fc9e1 Workaround for 'Permission denied - NUL' errors with JRuby on Windows.
    • 6bd7a51 Update copyright years.
    • 9905ca9 Fix directory traversal in Timezone.get when using Ruby data source
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • algorithm: .tripleDES, mode: .CBC is not working proper.

    algorithm: .tripleDES, mode: .CBC is not working proper.

    Hello @iosdevzone,

    I am working on iOS swift project that encrypts and decrypts transfer data with TDES 2key CBC algorithm. Luckily, I found your repo and tried to implement it for my project. Below is my testing crypto code.

    ` import Foundation import IDZSwiftCommonCrypto

    let algorithm = Cryptor.Algorithm.tripleDES let iv = arrayFrom(hexString: "00000000000000000000000000000000") let key = arrayFrom(hexString: "6522B4E171195BB218223A976C040111")

    let cryptor = Cryptor(operation: .encrypt, algorithm: .tripleDES, mode: .CBC, padding: .NoPadding, key: key, iv: iv) let cipherText = cryptor.update(arrayFrom(hexString: "11223344556677885A6E7E385162B7A3404142434445464748494A4B4C4D4E4F"))?.final() `

    It is working without error but the result is not right! I was expecting

    937745c20883a1bad1e04193722a1592378f81a8f1dc589157aeb0f7544fa1ba

    But Its result is

    669747ad72be1037380ea630796ce9e974d7433a1ff05f923f51718cadf95d80 Can you help us to solve this problem?

    Xcode 11.4 (11E146) Playground Settings iOS IDZSwiftCommonCrypto 0.13.0

    opened by Jagaa9a 1
  • Fix up CTR mode wrong options

    Fix up CTR mode wrong options

    when use CTR mode, options = 0 in iOS 10.3, CCCryptorCreateWithMode will return kCCUnimplemented, change options = CCModeOptions(kCCModeOptionCTR_BE) fix it.

    opened by Re-cover 1
Releases(0.13.0)
  • 0.13.0(Jul 19, 2019)

    iOS 13 beta removed the following mode constants:

    • kCCModeF8,
    • kCCModeLRW, and
    • kCCModeXTS.

    The first two were not actually implemented in CommonCrypto, according to comments in the header files. The last one may have been implemented, but IDZSwiftCommonCrypto never exposed some constants that would have been needed to use it.

    This release removes references to these constants.

    Source code(tar.gz)
    Source code(zip)
  • 0.12.0(May 22, 2019)

  • 0.11.3(Mar 22, 2019)

  • 0.9.3(Sep 22, 2017)

  • 0.9.2(Jun 20, 2017)

    • Project now sets "APPLICATION_EXTENSION_API_ONLY" to yes. See PR #63. • README.md updated to Swift 3 API. • Checked in new version of Jazzy docs.

    Source code(tar.gz)
    Source code(zip)
  • 0.9.1(Feb 23, 2017)

    Version 0.9.0 had a rather aggressive CocoaPods iOS deployment version (9.3). In response to user requests this release has the iOS deployment version set to 9.0.

    In addition the above, there are some minor script and documentation fixes.

    Source code(tar.gz)
    Source code(zip)
  • 0.9.0(Sep 25, 2016)

  • 0.8.3(Sep 25, 2016)

  • 0.8.1(Sep 24, 2016)

    This release adds support for building using Xcode 8 (in legacy Swift 2.3 mode).

    It is still possible to build in Xcode 7.3.1 too hence only bumping version from 0.8.0 -> 0.8.1.

    There are not source changes associated with this release, it is all build file changes (specifically the Xcode project and the .travis.yml file.)

    Source code(tar.gz)
    Source code(zip)
  • 0.8.0(Sep 24, 2016)

  • 0.7.4(Sep 24, 2016)

    This release fixes the Travis build, ensures coverage is only turned on in debug based configurations (PR #28) and removes a deprecated C-style loop.

    Source code(tar.gz)
    Source code(zip)
  • 0.7.2(Jan 15, 2016)

  • 0.7.1(Jan 12, 2016)

  • 0.7.0(Jan 9, 2016)

    Adds support for OS X, watch OS and tvOS.

    The (yucky) shell script GenerateCommonCryptoModule has now been replaced with a (lovely, doubley) Swift script GenerateCommonCryptoModule.swift

    Also fixes issues: #7 and #9

    Source code(tar.gz)
    Source code(zip)
Owner
idz
idz
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 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
Demonstration library for using the Secure Enclave on iOS

SecureEnclaveCrypto This project shows you how to create a keypair where as the private key is stored in the secure enclave sign a string / some data

Trail of Bits 272 Jan 7, 2023
BitWiser - A simple library to help you in dealing with bytes, bits and nibbles

BitWiser Bitwiser is a collection of methods and properties that makes you work

Andrea Finollo 19 Dec 27, 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 wrapper for Apple's Common Crypto library written in Swift.

IDZSwiftCommonCrypto A Swift wrapper for Apple's CommonCrypto library. IDZSwiftCommonCrypto works with both CocoaPods and Cathage. For more details on

idz 472 Dec 12, 2022
🐵Fooling around with Apples private framework AvatarKit

Fooling around with Apples private framework AvatarKit, the framework used in Messages.app for recording Animoji videos. If you are looking to create your own Animoji, take a look at SBSCustomAnimoji.

Simon Støvring 968 Dec 25, 2022
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
A feature-light wrapper around Core Data that simplifies common database operations.

Introduction Core Data Dandy is a feature-light wrapper around Core Data that simplifies common database operations. Feature summary Initializes and m

Fuzz Productions 33 May 11, 2022
Kukai Crypto Swift is a native Swift library for creating regular or HD wallets for the Tezos blockchain

Kukai Crypto Swift Kukai Crypto Swift is a native Swift library for creating regular and HD key pairs for the Tezos blockchain. Supporting both TZ1 (E

Kukai Wallet 2 Aug 18, 2022