2017-07-12 101 views
0

一次性加密方法CCCrypt的簽名是這樣的(從CommonCryptor.h):參數的如何讓CCCrypt在另一種模式下計算AES?

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) 

沒有一個似乎接受CCMode值(也許鬼祟,因爲所有的枚舉是整數?)。我曾嘗試將它與CCOptions參數結合使用,但無濟於事。這兩個枚舉不是選項,也不能毫不含糊地結合在一起。

它沒有明確記錄在那裏,但我從我在網上發現的與kCCAlgorithmAES使用的模式是CBC的東西中猜測。

如何更改AES模式CCCrypt的用途?

+0

如果您有權訪問ECB或CBC,實現其他模式非常容易。唯一的挑戰是正確實現每塊加密的計數器。 –

+0

@ArtjomB。是的,不,我不會自己去執行加密方法。這樣只有厄運和瘋狂的謊言。 – Raphael

+0

@zaph - 我希望看到你回答這個問題。你沒有基於Apple Common Crypto的加密庫嗎? – jww

回答

0

文檔說:

CCCrypt 無狀態的,一次性的加密或解密操作。 這基本上執行CCCrytorCreate() [原文如此], CCCryptorUpdate(),CCCryptorFinal()CCCryptorRelease()的序列。

現在,CCCryptorCreate似乎也不接受模式參數;事實上,我們認爲see CBC確實是硬編碼的(除了一個,有點武斷,使我們能夠使用ECB):

/* Determine mode from options - old call only supported ECB and CBC 
    we treat RC4 as a "mode" in that it's the only streaming cipher 
    currently supported 
*/ 
if(alg == kCCAlgorithmRC4) mode = kCCModeRC4; 
else if(options & kCCOptionECBMode) mode = kCCModeECB; 
else mode = kCCModeCBC; 

如果我們想使用另一種模式,我們必須使用CCCryptorCreateWithMode。所以,不幸的是,似乎不可能改變CCCrypt的模式。

相關問題