0

I want to decrypt a DES encrypted String with CommonCrypto and therefore i have to generate a key from a given passphrase.

I found the following function in Apple's API reference: SecKeyGenerateSymmetric

But when I import Security in my swift file this function is not available while other functions of the framework are available (eg. SecKeyGeneratePair).

Has this function been replaced by some other?

Or is there any other way to generate a DES key in Swift 3?

ndreisg
  • 1,119
  • 13
  • 33
  • Note: Do not use DES in new code, it is not secure and has ben superseded by AES. For existing code it is best to make the effort to change to AES, if backward compatibility is needed consider using a version indicator and supporting both AES and DES for compatibility. – zaph May 18 '17 at 08:54

1 Answers1

1

In order to use Common Crypto with Swift it is necessary to add a bridging header:

#import <CommonCrypto/CommonCrypto.h>

Add the Security.framework to the project.

Note:

When generating a key from a password (key derivation) the same method and parameters ned to be used. There are several such methods commonly used, PBKDF2 is one often used and suggested by NIST. Do you know the method and parameters used for the key derivation?

zaph
  • 111,848
  • 21
  • 189
  • 228
  • Thanks for the answer. I already imported CommonCrypto with a BridgingHeader. But I just found out, that it seems to be unnecessary to generate a key for DES decryption. I can simply use a 8 byte string and convert it to data with UTF8 encoding. I'm now able to call CCCrypt function without any errors but my result is still empty... I will update my question soon! – ndreisg May 18 '17 at 09:41
  • I posted a new question for this problem, maybe you can help me with this one too? [Decrypting DES with CommonCrypto in Swift 3](http://stackoverflow.com/questions/44044816/decrypting-des-with-commoncrypto-in-swift-3) – ndreisg May 18 '17 at 10:09
  • A secure key is generally an array of random characters and that is best created using Common Crypto `SecRandomCopyBytes`. – zaph May 18 '17 at 10:58