Apple's cryptography framework. Contains functions for generating commonly-used hashes and cryptographic functions.
Questions tagged [commoncrypto]
209 questions
190
votes
16 answers
Importing CommonCrypto in a Swift framework
How do you import CommonCrypto in a Swift framework for iOS?
I understand how to use CommonCrypto in a Swift app:
You add #import to the bridging header.
However, Swift frameworks don't support bridging headers. The…

hpique
- 119,096
- 131
- 338
- 476
43
votes
11 answers
AES encryption in swift
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…

Ankita Shah
- 2,178
- 3
- 25
- 42
38
votes
11 answers
CommonHMAC in Swift
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…

Matt Donnelly
- 417
- 1
- 4
- 6
21
votes
2 answers
Signing and Verifying on iOS using RSA
How to sign and verify some data on iOS with an RSA key (preferably using the system own libcommonCrypto)?

miho
- 11,765
- 7
- 42
- 85
20
votes
1 answer
When To Check the "This Application Uses Encryption" Box?
When submitting or updating an app, one question you are faced with is:
Have you added or made changes to encryption features since you last
uploaded a binary for this product?
Image:
My question is, if I use the encryption you get from the…

Sam
- 26,946
- 12
- 75
- 101
19
votes
3 answers
Issue using CCCrypt (CommonCrypt) in Swift
I am porting a working Objective-C Category (NSData+AESCrypt.m) to Swift and I have found an issue working with the pointers. The code for the encrypting part in Swift compiles correctly, but generates a runtime EXEC_BAD_ACCES error.
The code I…

eharo2
- 2,553
- 1
- 29
- 39
17
votes
3 answers
PBKDF2 using CommonCrypto on iOS
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…

AnthonyM
- 1,115
- 2
- 10
- 20
17
votes
3 answers
Swift Calculate MD5 Checksum for Large Files
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 =…

Mike Walker
- 2,944
- 8
- 30
- 62
13
votes
1 answer
How to use common crypto and/or calculate sha256 in swift 2 & 3
I am trying to make hash a password value according to sha256. I already search this but there is no info about swift 2. This solution did not worked for me
func sha256(data:String) -> String {
let data =…

mesopotamia
- 393
- 1
- 5
- 19
12
votes
4 answers
Data signed on iOS can't be verified in Java
I have some data that I'm signing on iOS with SecKeyRawSign using Elliptic Curve private key. However, verifying that data in Java using Signature.verify() returns false
The data is a random 64 bit integer, split into bytes like so
uint64_t nonce…

mag_zbc
- 6,801
- 14
- 40
- 62
11
votes
4 answers
How can I hash a file on iOS using swift 3?
I have a number of files that will live on a server. Users have the ability to create these kinds of files (plists) on-device which will then upload to said server (CloudKit). I would like to unique them by content (the uniquing methodology should…

iOS Gamer
- 476
- 5
- 8
11
votes
3 answers
How to use CommonCrypto for PBKDF2 in Swift 2 & 3
I am trying to use CommonCrypto to hash passwords using PBKDF2 in Swift 2 because of its high performance and also due to it being open source
I've already managed to get CommonCrypto working in Swift using module maps but can someone tell me the…

Rvv
- 201
- 2
- 8
11
votes
2 answers
Swift: How to call CCKeyDerivationPBKDF from Swift
I'm trying to call CCKeyDerivationPBKDF from Swift.
I've imported the required header in my Project-Bridging-Header.h:
#import
(Btw, the bridging header appears to be working correctly for importing other…

Daniel
- 8,794
- 4
- 48
- 71
10
votes
4 answers
CCCrypt decrypting in AES CBC works even without IV
I have a confusing problem, where decrypting a file which was encrypted using CCCrypt's AES-CBC mode with a randomized, 16byte IV produces the exact same output whether I pass in the same correct IV used for encryption or none at all.
What I expect:…

Dennis
- 2,223
- 3
- 27
- 36
10
votes
1 answer
What would happen if kSecAttrIsPermanent is set to NO?
What is the usage of the kSecAttrIsPermanent attribute when using Apples libcommonCrypto.dylib on iOS?
Apples documentation says:
The corresponding value is of type CFBooleanRef and indicates whether
this cryptographic key is to be stored…

miho
- 11,765
- 7
- 42
- 85