commoncrypto

iPhone Public-Key Encryption SecKeyEncrypt returns error 9809 (errSSLCrypto)

笑着哭i 提交于 2019-12-05 02:52:54
问题 I am trying to use the iPhone's PKI libraries to encrypt a short string (12345678), but I keep getting the error -9809 (i.e. errSSLCrypto) whenever I try to use SecKeyEncrypt. The SecureTransport.h header file describes this error simply as "underlying cryptographic error", which wasn't very meaningful. My code is as follows: - (NSData *)encryptDataWithPublicKey:(NSString *)plainText { OSStatus result = -1; NSData *plainTextData = [plainText dataUsingEncoding:NSASCIIStringEncoding]; size_t

HMAC SHA512 using CommonCrypto in Swift 3.1 [duplicate]

纵饮孤独 提交于 2019-12-04 20:41:42
This question already has an answer here: CommonHMAC in Swift 10 answers I'm trying to encrypt data to send to the API. The API requires the data to be sent as hmac_sha512 encrypted hash. I've found various examples of how it possibly could have been done for sha1 and others (not sha512 ) and also in older versions of Swift. None of the examples that I tried work for swift 3.1 Any help in the right direction will be appreciated. Edit: In PHP, I successfully send it using: $sign = hash_hmac('sha512', $post_data, $this->secret); Edit 2: I did add briding header , I don't know what to do next! As

Anyone else having trouble with iOS 5 encryption?

廉价感情. 提交于 2019-12-04 14:16:04
Have a (rather complex) app that works fine on iOS 4 but fails on iOS 5 with a decryption problem. It's decrypting a SQLite DB page, and the last 16 bytes do not appear to be properly decrypted. Does this ring a bell with anyone? Update I've determined that, when CCCryptorUpdate is given a buffer length of 1008 (1024 - 16) it only decrypts 992 bytes (as reported in the dataOutMoved parameter). This would be OK if CCCryptorFinal returned the remaining bytes, but it reports zero bytes moved. However, CCCryptorFinal is reporting a -4304 return code (which is an unhelpful kCCDecodeError). Update 2

iOS Core Data encryption using NSValueTransformer

这一生的挚爱 提交于 2019-12-04 14:02:04
I'm experimenting with encrypting data with Core Data and CommonCrypto. I am trying to use a NSValueTransformer to lazily encrypt and decrypt. However when I'm now trying save the encrypted data to the persistent store coordinator, it fails. Every time im trying to save my data to the database, it gives me: -[__NSCFString bytes]: unrecognized selector sent to instance I'm sure it's some sort of database and NSManagedObject mismatch, but I can't figure it out. I feel it's probably rather simple, but I can't find the solution. My code: NSValueTransformer class TryHardEncryption:

Issue decrypting with CommonCrypto in Swift

不羁的心 提交于 2019-12-04 12:11:54
I am working in a Swift-only crypt/decrypt Extension for String and NSData , and the crypt part is working based in the answer provided by @Zaph in the linked question: Issue using CCCrypt (CommonCrypt) in Swift The crypt output was tested using the good old NSData+AESCrypt.m Category in Objective-C I have been working in the decrypt part with an issue: The code compiles and runs fine, but the result is not the expected text originally encrypted. extension NSData { func AES256EncryptDataWithKey(key: String) -> NSData { let keyData: NSData! = (key as NSString).dataUsingEncoding

Are CC_MD5() and CC_SHA1() available in iOS 4?

时光总嘲笑我的痴心妄想 提交于 2019-12-04 02:39:06
I am looking to make use of MD5 or SHA-1 in my iOS application targeted at iOS 4 and later. I use the CC_MD5() and CC_SHA1() functions from CommonCrypto/CommonDigest.h. It seems to work fine on an iPhone running iOS 4.1 and in the iPhone 4.0 simulator, but I am concerned because the functions are declared as follows in the iOS 5 SDK that comes with XCode 4.2: extern unsigned char *CC_MD5(const void *data, CC_LONG len, unsigned char *md) __OSX_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_5_0); extern unsigned char *CC_SHA1(const void *data, CC_LONG len, unsigned char *md) __OSX_AVAILABLE_STARTING(_

iPhone Public-Key Encryption SecKeyEncrypt returns error 9809 (errSSLCrypto)

☆樱花仙子☆ 提交于 2019-12-03 21:16:45
I am trying to use the iPhone's PKI libraries to encrypt a short string (12345678), but I keep getting the error -9809 (i.e. errSSLCrypto) whenever I try to use SecKeyEncrypt. The SecureTransport.h header file describes this error simply as "underlying cryptographic error", which wasn't very meaningful. My code is as follows: - (NSData *)encryptDataWithPublicKey:(NSString *)plainText { OSStatus result = -1; NSData *plainTextData = [plainText dataUsingEncoding:NSASCIIStringEncoding]; size_t plainTextLength = [plainTextData length]; SecTrustRef trustRef; SecTrustResultType trustResult;

How to use common crypto and/or calculate sha256 in swift 2 & 3

梦想的初衷 提交于 2019-12-03 16:36:59
问题 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 = self.dataUsingEncoding(NSUTF8StringEncoding)! var digest = [UInt8](count:Int(CC_SHA256_DIGEST_LENGTH), repeatedValue: 0) CC_SHA256(data.bytes, CC_LONG(data.length), &digest) let hexBytes = digest.map { String(format: "%02hhx", $0) } return hexBytes.joinWithSeparator("") } It gives error: Use

implementing AES256 encryption into IOS

别等时光非礼了梦想. 提交于 2019-12-03 09:39:22
This is my java code. Now I want to implement same functionality in Objective-C. Cipher encryptCipher; IvParameterSpec iv = new IvParameterSpec(key); SecretKeySpec skeySpec = new SecretKeySpec(key, "AES"); encryptCipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); encryptCipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv); byte[] encrypted = encryptCipher.doFinal(dataToEncrypt.getBytes()); Log.d("TAG", "encrypted string:" + Base64.encodeToString(encrypted, Base64.DEFAULT)); return Base64.encodeToString(encrypted, Base64.DEFAULT).trim(); This is my iOS implementation - (NSData *

How to use common crypto and/or calculate sha256 in swift 2 & 3

被刻印的时光 ゝ 提交于 2019-12-03 05:47:14
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 = self.dataUsingEncoding(NSUTF8StringEncoding)! var digest = [UInt8](count:Int(CC_SHA256_DIGEST_LENGTH), repeatedValue: 0) CC_SHA256(data.bytes, CC_LONG(data.length), &digest) let hexBytes = digest.map { String(format: "%02hhx", $0) } return hexBytes.joinWithSeparator("") } It gives error: Use of unresolved identifier CC_SHA256_DIGEST_LENGTH Add a bridging header and add the import to it: