//
//  CCAESChiper.swift
//  punchnet
//
//  Created by 安礼成 on 2026/3/17.
//
import Foundation

struct CCAESChiper: CCDataCipher {
    private let aesKey: Data
    
    init(key: Data) {
        self.aesKey = key
    }
    
    func decrypt(cipherText: Data) throws -> Data {
        let ivData = Data(aesKey.prefix(16))
        return try CC.crypt(.decrypt, blockMode: .cbc, algorithm: .aes, padding: .pkcs7Padding, data: cipherText, key: aesKey, iv: ivData)
    }
    
    func encrypt(plainText: Data) throws -> Data {
        let ivData = Data(aesKey.prefix(16))
        
        return try CC.crypt(.encrypt, blockMode: .cbc, algorithm: .aes, padding: .pkcs7Padding, data: plainText, key: aesKey, iv: ivData)
    }
    
}
