commoncrypto

Swift: How to call CCKeyDerivationPBKDF from Swift

淺唱寂寞╮ 提交于 2019-11-28 23:38:36
I'm trying to call CCKeyDerivationPBKDF from Swift. I've imported the required header in my Project-Bridging-Header.h: #import <CommonCrypto/CommonKeyDerivation.h> (Btw, the bridging header appears to be working correctly for importing other Objective C code in my project). In Xcode I can jump from my .swift file to the definition shown here: int CCKeyDerivationPBKDF( CCPBKDFAlgorithm algorithm, const char *password, size_t passwordLen, const uint8_t *salt, size_t saltLen, CCPseudoRandomAlgorithm prf, uint rounds, uint8_t *derivedKey, size_t derivedKeyLen) Finally, when I attempt to call the

Signing and Verifying on iOS using RSA

懵懂的女人 提交于 2019-11-28 17:10:11
问题 How to sign and verify some data on iOS with an RSA key (preferably using the system own libcommonCrypto )? 回答1: Since there hasn't been nearly any knowledge about signing and verifying found on StackOverflow and the Apple docs, I had to manually browse around in the iOS header files and found SecKeyRawSign and SecKeyRawVerify . The following lines of code seem to work. Signing NSData (using SHA256 with RSA): NSData* PKCSSignBytesSHA256withRSA(NSData* plainData, SecKeyRef privateKey) { size_t

How to encrypt using AES GCM on iOS?

纵然是瞬间 提交于 2019-11-28 11:28:46
问题 I need to encrypt/decrypt some data using AES encryption on GCM mode, but apparently this can't be done with the CommonCrypto API. This has been asked previously here, but the accepted answer is not what I'm looking for, since I need to use this specific algorithm. Any ideas? Should I use OpenSSL? Because I've heard that there are some bugs when using it in iOS. I'm looking for an answer in Swift, but Objective-C would be fine as well. 回答1: There is some GCM crypt functions in the

Swift Calculate MD5 Checksum for Large Files

懵懂的女人 提交于 2019-11-27 16:31:19
问题 I'm working on creating the MD5 Checksum for large video files. I'm currently using the code: extension NSData { func MD5() -> NSString { let digestLength = Int(CC_MD5_DIGEST_LENGTH) let md5Buffer = UnsafeMutablePointer<CUnsignedChar>.allocate(capacity: digestLength) CC_MD5(bytes, CC_LONG(length), md5Buffer) let output = NSMutableString(capacity: Int(CC_MD5_DIGEST_LENGTH * 2)) for i in 0..<digestLength { output.appendFormat("%02x", md5Buffer[i]) } return NSString(format: output) } } But that

Swift: How to call CCKeyDerivationPBKDF from Swift

戏子无情 提交于 2019-11-27 15:09:51
问题 I'm trying to call CCKeyDerivationPBKDF from Swift. I've imported the required header in my Project-Bridging-Header.h: #import <CommonCrypto/CommonKeyDerivation.h> (Btw, the bridging header appears to be working correctly for importing other Objective C code in my project). In Xcode I can jump from my .swift file to the definition shown here: int CCKeyDerivationPBKDF( CCPBKDFAlgorithm algorithm, const char *password, size_t passwordLen, const uint8_t *salt, size_t saltLen,

MD5 3DES encryption Swift

我的梦境 提交于 2019-11-27 07:19:07
问题 I have an app that must send login credentials that have been encrypted first by MD5 and then by 3DES. I have managed to use CryptoSwift to encrypt the string by MD5. However I cannot find anything to encrypt by 3DES on Swift. I have tried CommonCrypto. As far as I can tell this is in C but could be imported into Objective C with a bridging header. I have found a few articles and tutorials that tell me how to import CommonCrypto into Swift, either by a bridging header(with the warning it will

PBKDF2 using CommonCrypto on iOS

本小妞迷上赌 提交于 2019-11-27 06:38:41
I'm trying to use CommonCrypto to generate keys using PBKDF2 but I can't seem to import CommonCrypto/CommonKeyDerivation.h , I just errors that it is not found. Any ideas? edit: I should probably mention I have already added the security framework and I can import all of the other CommonCrypto headers. Here's how i generate AES256 keys. The only interesting this is that i get CommonCrypto to estimate for me how many rounds to use. It seems pretty straightforwards. #import <CommonCrypto/CommonKeyDerivation.h> ... // Makes a random 256-bit salt - (NSData*)generateSalt256 { unsigned char salt[32]

AES encryption in swift

此生再无相见时 提交于 2019-11-26 18:43:18
I'm trying to implement AES encryption in swift. The encryption decryption for Android and C# is working properly. I need to implement it in swift. It's current code for android and C# is followed by this. I tried to use CryptoSwift Cross platform AES encryption But none of it work. When I send the encrypted string on server it's not been decrypted. Any help will be appreciated Be sure to use the same parameters which seem to be AES with CBC mode with iv, PKCS5Padding (actually PKCS#7) padding and a 16-byte (128-bit) key. PKCS#5 padding and PKCS#7 padding are essentially the same, sometimes

PBKDF2 using CommonCrypto on iOS

China☆狼群 提交于 2019-11-26 12:55:05
问题 I\'m trying to use CommonCrypto to generate keys using PBKDF2 but I can\'t seem to import CommonCrypto/CommonKeyDerivation.h , I just errors that it is not found. Any ideas? edit: I should probably mention I have already added the security framework and I can import all of the other CommonCrypto headers. 回答1: Here's how i generate AES256 keys. The only interesting this is that i get CommonCrypto to estimate for me how many rounds to use. It seems pretty straightforwards. #import <CommonCrypto

CommonHMAC in Swift

邮差的信 提交于 2019-11-26 12:16:41
I'm trying to create a HMAC SHA-1 hash of a string in Swift but can't figure out how to interact with the APIs as it doesn't seem to be importing the CommonCrypto framework. I've tried various different forms of "import CommonCrypto" and creating a bridging header file but none of it made a difference. The odd thing is that if I create an Objective-C class, I'm able to interact with APIs without any problems, so this seems to be unique to Swift. Also if anyone could tell me what the equivalent of uint8_t digest[CC_SHA1_DIGEST_LENGTH] is in Swift I'd be very grateful You can do it in Swift.