如何在Swift 3

时间:2017-10-16 00:18:48

标签: swift encryption aes

我需要使用AES-CCM在Swift 3中加密和解密。 我已经安装了模块CryptoSwift,我的应用程序可以像这样做正常的AES128:

//aes
let input: Array<UInt8> = [0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f]

let key: Array<UInt8> = [0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f]
let iv: Array<UInt8> = AES.randomIV(AES.blockSize)

do {
    let encrypted = try AES(key: key, iv: iv, blockMode: .CBC, padding: .pkcs7).encrypt(input)
    print(encrypted)
    let decrypted = try AES(key: key, iv: iv, blockMode: .CBC, padding: .pkcs7).decrypt(encrypted)
    print(decrypted)
} catch {
    print(error)
}

但是我找不到一种方法来做CCM模式,它没有IV但是一个短于16字节的nonce。

CryptoSwift能够执行AES-CCM还是我必须寻找其他模块? 请给我一些建议。

0 个答案:

没有答案