commoncrypto

How to add salt to AES Encryption in iOS and decrypting it using objective c

人走茶凉 提交于 2020-12-21 04:19:32
问题 I have appended the IV to the AES Encryption/decryption code by using objective c in iOS and able to decrypt and encrypt the same. Right now I am trying to add the salt to the AES Encryption but unfortunately its not working for me. Here is the code: I have also edited with Android salt generation code for just to check whether my salt generation is valid or not in iOS Encryption code: + (NSData*)encryptData:(NSData*)data key:(NSData*)key error:(NSError **)error; { NSData *salt = [self

How to add salt to AES Encryption in iOS and decrypting it using objective c

不打扰是莪最后的温柔 提交于 2020-12-21 04:18:25
问题 I have appended the IV to the AES Encryption/decryption code by using objective c in iOS and able to decrypt and encrypt the same. Right now I am trying to add the salt to the AES Encryption but unfortunately its not working for me. Here is the code: I have also edited with Android salt generation code for just to check whether my salt generation is valid or not in iOS Encryption code: + (NSData*)encryptData:(NSData*)data key:(NSData*)key error:(NSError **)error; { NSData *salt = [self

lib commonCrypto not available for iOS simulator?

廉价感情. 提交于 2020-01-30 04:21:08
问题 I've been adding libCommonCrypto.dylib to my project to do md5 hash verification. Works all proper on the iPhone (iOS 5.1), but when I try to run it on the simulator, I get this error: ld: library not found for -lcommonCrypto clang: error: linker command failed with exit code 1 (use -v to see invocation) I'm a bit clueless why this happens. I added the commonCrypto to the project target -> build phase -> link binary with libraries. Is there any additional step required to get it working also

SecKeyRawVerify verifies on mac but fails with -9809 on iOS

北战南征 提交于 2020-01-16 03:50:07
问题 I need to digitally sign on mac some data and then verify it on iOS. So I generated RSA keypair and certificate for public key in DER format with open ssl (tried generation with SecKeyGeneratePair but then it is harder to import Public key to iOS and SecKeyRawVerify still doesn't work with the same result), and signed my data on Mac app. Then if I verify this data on iOS verification fails with -9809 error code, but if execute the same code on mac verification succeeds. Here is my code for

Swift 5 + kCCDecrypt (CommonCrypto): Failing to decrypt

一曲冷凌霜 提交于 2020-01-11 10:17:08
问题 Trying to write my own encrypt/decrypt functions in Swift 5 , based on tons of other similar questions -- and failing miserably. I'm using CommonCrypto + CCCrypt to encrypt/decrypt (AES, 256 key, random iv). I'm favouring NSData.bytes over withUnsafeBytes (which is just too confusing in Swift 5 ). My encrypt function goes like this: func encrypt(_ string: String) throws -> Data { guard let dataToEncrypt: Data = string.data(using: .utf8) else { throw AESError.stringToDataFailed } // Seems like

Converting objective-c code to swift

天涯浪子 提交于 2020-01-02 10:58:54
问题 I really need some help to convert the objective-c code to swift using CryptoSwift . I'm not sure how to use functions like: bzero , getCString , malloc in Swift. +(NSData*)encryptData:(NSData*)data { static NSString *key = @"BitCave012345678"; char keyPtr[kCCKeySizeAES128+1]; bzero(keyPtr, sizeof(keyPtr)); [key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding]; NSUInteger dataLength = [data length]; size_t bufferSize = dataLength + kCCBlockSizeAES128; void *buffer =

CCCrypt decrypting in AES CBC works even without IV

此生再无相见时 提交于 2019-12-29 05:25:17
问题 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: using a NULL IV for decrypting should not result in a correct decryption. What I observe: using a NULL IV results in the same result as with the IV used for encryption. Below for sake of completeness, here's the important code snippets, iv is

Decrypt a base64 string using C# generated by iOs CCCrypt function using AES

霸气de小男生 提交于 2019-12-25 03:49:15
问题 Could someone please help decrypt the base64 string generated by iOS code below into its C# equivalent. I am trying to end up with "Meet me at the secret location at 8pm" within c#. iOS generated the following encryption: qd+SGaij5KSBScuLs3TpJS/3Dew8fHTudcs/5MG7Q1kqcrZzZycMgTcQuEEEED5f This iOS code successfully encrypts and decrypts data as required within XCode 6. Thank you in advance for your help and support. Darren #import <CommonCrypto/CommonCryptor.h> - (void)viewDidLoad { [super

iOS Core Data encryption using NSValueTransformer

孤街浪徒 提交于 2019-12-21 20:37:54
问题 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

Issue decrypting with CommonCrypto in Swift

孤者浪人 提交于 2019-12-21 19:57:31
问题 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