CommonCrypto加密解密参数说明
CCCryptorStatus CCCrypt(
CCOperation op, /* kCCEncrypt, etc. */
CCAlgorithm alg, /* kCCAlgorithmAES128, etc. */
CCOptions options, /* kCCOptionPKCS7Padding, etc. */
const void *key,
size_t keyLength,
const void *iv, /* optional initialization vector */
const void *dataIn, /* optional per op and alg */
size_t dataInLength,
void *dataOut, /* data RETURNED here */
size_t dataOutAvailable,
size_t *dataOutMoved)
__OSX_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_2_0);
参数说明
enum {
kCCAlgorithmAES128 = 0,
kCCAlgorithmAES = 0,
kCCAlgorithmDES,
kCCAlgorithm3DES,
kCCAlgorithmCAST,
kCCAlgorithmRC4,
kCCAlgorithmRC2,
kCCAlgorithmBlowfish
};
typedef uint32_t CCAlgorithm;
-
CCOptions options
可以使用|
符号,枚举如下
enum {
/* options for block ciphers */
kCCOptionPKCS7Padding = 0x0001,
kCCOptionECBMode = 0x0002
/* stream ciphers currently have no options */
};
typedef uint32_t CCOptions;
-
const void *key
加密或解密的钥匙[2]
-
size_t keyLength
钥匙的内存长度,请根据加密算法从以下枚举中选择
enum {
kCCKeySizeAES128 = 16,
kCCKeySizeAES192 = 24,
kCCKeySizeAES256 = 32,
kCCKeySizeDES = 8,
kCCKeySize3DES = 24,
kCCKeySizeMinCAST = 5,
kCCKeySizeMaxCAST = 16,
kCCKeySizeMinRC4 = 1,
kCCKeySizeMaxRC4 = 512,
kCCKeySizeMinRC2 = 1,
kCCKeySizeMaxRC2 = 128,
kCCKeySizeMinBlowfish = 8,
kCCKeySizeMaxBlowfish = 56,
};
-
const void *iv
初始化矢量,传NULL
即可
-
const void *dataIn
需要加密的数据[3]
-
size_t dataInLength
加密数据的内存长度[4]
-
void *dataOut
数据输出的地址
-
size_t dataOutAvailable
为数据输出预留的内存大小
-
size_t *dataOutMoved
输出的位移
-
注意加密和解密时算法要一致
-
请注意类型转化成C类型,笔者使用 UTF8String
-
请注意类型转化成C类型,笔者使用 bytes
-
内存长度的计算与数据类型有关,请自行百度,这里不做说明