我使用CryptoSwift加密一些数据,然后使用Node.js加密相同的数据。但结果不一样。我问了作者,他说这不是窃听器。
我不知道我在哪里犯了错。下面是我如何使用CryptoSwift和Node.js的图片:
密码算法: aes-256-cfb
键: 32字节1
四: 16字节0
CryptoSwift: develop分支0.1.1
Node.js: LTS 4.2.3
CryptoSwift加密数据
用Node.js 4.2.3加密的数据
这是快速代码:
func testAES() {
let key = [UInt8](count: 32, repeatedValue: 1)
let iv = [UInt8](count: 16, repeatedValue: 0)
print(key)
print(iv)
let aes256cfb = try! AES(key: key, iv: iv, blockMode: .CFB)
let en1 = try! aes256cfb.encrypt([0x5, 0x77], padding: nil)
print(en1.map({ i in String(format: "%2x", i)}))
let en2 = try! aes256cfb.encrypt([0x5, 0x0, 0x3, 0x89, 0x20], padding: nil)
print(en2.map({ i in String(format: "%2x", i)}))
}
CryptoSwift:
["77", "ef"]
["77", "98", "c9", "2c", "45"]
Node.js:
<Buffer 77 ef>
<Buffer cf a5 66 8a 3e>您可以看到,前两个字节是相同的,但其余的则不同。为什么?我的代码写错了吗?我对密码不太了解,请告诉我原因。非常感谢。
发布于 2015-12-08 01:45:50
发布于 2015-12-12 22:35:59
回答这个问题。
NodeJS代码加密0x5、0x77、0x5、0x0、0x3、0x89、0x20,而CryptoSwift代码加密0x5、0x77、0x5、0x0、0x3、0x89、0x20。这就是你得到不同结果的原因。
https://stackoverflow.com/questions/34146316
复制相似问题