我正在尝试与CryptoJS
加密相同的文本加密。但是这里我与您共享的URL都不相同,我需要在Swift中进行相同的加密。请帮助我,在这里我也附上我的代码。
Demo CryptoJS encryption
在此URL中,我们使用CryptoJS
和ECB
进行pkcs7
加密。我在ios中执行的代码相同,但不相同
import UIKit
import Foundation
import CryptoSwift
class CryptoViewController: UIViewController {
let KEY = "0123456789123456"
override func viewDidLoad() {
super.viewDidLoad()
self.aesCBC_Encrypt(AES_KEY: KEY, payload: "Hello World!")
}
func aesCBC_Encrypt(AES_KEY: String,payload: String) -> String {
var result = ""
do {
let key: [UInt8] = Array(AES_KEY.utf8) as [UInt8]
let iv = AES.randomIV(AES.blockSize)
let bytes = payload.bytes
let aes = try! AES(key: key, blockMode: ECB(), padding: .pkcs7)
//let encrypted = try aes.encrypt(Array(self.utf8))
let encrypted = try aes.encrypt(bytes)
print("encrypted: \(encrypted)")
result = encrypted.toHexString()
print("AES Encryption Result: \(result)")
} catch {
print("Error: \(error)")
}
return result
}
}
从我的代码中,我得到这个结果
AES Encryption Result: 1b8019c2add38f33de9099aefd5369f5
但是当我尝试从CryptoJS加密时,我得到的结果
Encrypted Text:
Aeoo7GP6b4l/Pdxz2RS+qA==