commoncrypto

Interoperability of AES CTR mode?

自作多情 提交于 2019-12-07 09:50:22
问题 I use AES128 crypto in CTR mode for encryption, implemented for different clients (Android/Java and iOS/ObjC). The 16 byte IV used when encrypting a packet is formated like this: <11 byte nonce> | <4 byte packet counter> | 0 The packet counter (included in a sent packet) is increased by one for every packet sent. The last byte is used as block counter, so that packets with fewer than 256 blocks always get a unique counter value. I was under the assumption that the CTR mode specified that the

For AES128 using CCCrypt() can the key be longer than 128 bits?

血红的双手。 提交于 2019-12-07 05:51:35
问题 I am using the CCCrypt method. Can I use a longer key than than 128bit? Can it be arbitrarily long? Or perhaps multiples of 128? If so how would I do this? I didn't think this woas possible but I found this text: here Some algorithms such as AES and RSA allow for keys of different lengths , but others are fixed, such as DES and 3DES. Encryption using a longer key generally implies a stronger resistance to message recovery. As usual, there is a trade off between security and time, so choose

SecKeyGetBlockSize or SecKeyRawVerify for Public Key throw EXC_BAD_ACCESS code=2

眉间皱痕 提交于 2019-12-07 05:06:19
问题 Upon trying to implement Security.Framework SecKeyRawVerify iOS function from Apple's example, programm halts with bad pointer error (EXC_BAD_ACCESS code=2). Any help or suggestions would be appreciated. Here is my code: - (BOOL)verifySignature:(NSData *)plainText signature:(NSData *)sig { size_t signedHashBytesSize = 0; OSStatus sanityCheck = noErr; SecKeyRef publicKeyA = NULL; NSMutableDictionary * queryPublicKeyA = [[NSMutableDictionary alloc] init]; NSData * publicTag = [NSData

HMAC SHA512 using CommonCrypto in Swift 3.1 [duplicate]

筅森魡賤 提交于 2019-12-06 14:58:34
问题 This question already has answers here : CommonHMAC in Swift (10 answers) Closed 2 years ago . 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

Converting objective-c code to swift

淺唱寂寞╮ 提交于 2019-12-06 11:58:24
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 = malloc(bufferSize); size_t numBytesEncrypted = 0; CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt,

Anyone else having trouble with iOS 5 encryption?

▼魔方 西西 提交于 2019-12-06 07:55:05
问题 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.

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

假如想象 提交于 2019-12-05 18:26:29
问题 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);

SecKeyGetBlockSize or SecKeyRawVerify for Public Key throw EXC_BAD_ACCESS code=2

半世苍凉 提交于 2019-12-05 10:55:44
Upon trying to implement Security.Framework SecKeyRawVerify iOS function from Apple's example, programm halts with bad pointer error (EXC_BAD_ACCESS code=2). Any help or suggestions would be appreciated. Here is my code: - (BOOL)verifySignature:(NSData *)plainText signature:(NSData *)sig { size_t signedHashBytesSize = 0; OSStatus sanityCheck = noErr; SecKeyRef publicKeyA = NULL; NSMutableDictionary * queryPublicKeyA = [[NSMutableDictionary alloc] init]; NSData * publicTag = [NSData dataWithBytes:publicKeyAIdentifier length:strlen((const char *)publicKeyAIdentifier)]; // // Set the public key

For AES128 using CCCrypt() can the key be longer than 128 bits?

房东的猫 提交于 2019-12-05 10:49:12
I am using the CCCrypt method. Can I use a longer key than than 128bit? Can it be arbitrarily long? Or perhaps multiples of 128? If so how would I do this? I didn't think this woas possible but I found this text: here Some algorithms such as AES and RSA allow for keys of different lengths , but others are fixed, such as DES and 3DES. Encryption using a longer key generally implies a stronger resistance to message recovery. As usual, there is a trade off between security and time, so choose the key length appropriately. How does AES allow for different lengths, does it ignore the bits higher

Data signed on iOS can't be verified in Java

空扰寡人 提交于 2019-12-05 03:36:17
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 = (some 64 bit integer) NSData *nonceData = [NSData dataWithBytes: &nonce length: sizeof(nonce)]; From that data I'm creating a SHA256 digest int digestLength = CC_SHA256_DIGEST_LENGTH; uint8_t *digest = malloc(digestLength); CC_SHA256(nonceData.bytes, (CC_LONG)nonceData.length, digest); NSData *digestData = [NSData dataWithBytes:digest length