From dd85bb2d0c89d63d62df68ebc0f53f84429b2f6f Mon Sep 17 00:00:00 2001 From: Han Chunlong Date: Wed, 30 Jul 2014 11:57:16 +0800 Subject: [PATCH] fix the condition if keydata's length is 16 or 24 Method:FixKeyLengths case:kCCAlgorithmAES128, fix the condition if keydata's length is 16 or 24 --- NSData+CommonCrypto.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/NSData+CommonCrypto.m b/NSData+CommonCrypto.m index 47dbd3d..b0cd7fa 100644 --- a/NSData+CommonCrypto.m +++ b/NSData+CommonCrypto.m @@ -282,11 +282,11 @@ static void FixKeyLengths( CCAlgorithm algorithm, NSMutableData * keyData, NSMut { case kCCAlgorithmAES128: { - if ( keyLength < 16 ) + if ( keyLength <= 16 ) { [keyData setLength: 16]; } - else if ( keyLength < 24 ) + else if ( keyLength <= 24 ) { [keyData setLength: 24]; } @@ -543,4 +543,4 @@ - (NSData *) HMACWithAlgorithm: (CCHmacAlgorithm) algorithm key: (id) key return ( [NSData dataWithBytes: buf length: (algorithm == kCCHmacAlgMD5 ? CC_MD5_DIGEST_LENGTH : CC_SHA1_DIGEST_LENGTH)] ); } -@end \ No newline at end of file +@end