Encryption 为什么是IV="&引用;CryptoSwift中的加密在Swift5上不起作用?

Encryption 为什么是IV="&引用;CryptoSwift中的加密在Swift5上不起作用?,encryption,swift5,cryptoswift,Encryption,Swift5,Cryptoswift,我尝试加密密码时出错。我找不到为什么encryption(iv=“”)在swift 3上运行良好,但现在在swift 5中无法使用iv=“”。我该如何解决这个问题 userText = userText.replacingOccurrences(of: "\\s+", with: "", options: .regularExpression, range: nil) let request:NSMutableURLRequest! let capcha:

我尝试加密密码时出错。我找不到为什么
encryption(iv=“”)
在swift 3上运行良好,但现在在swift 5中无法使用
iv=“”
。我该如何解决这个问题

userText = userText.replacingOccurrences(of: "\\s+", with: "", options: .regularExpression, range: nil)
let request:NSMutableURLRequest!
let capcha:String! = ""
let encryptedBase64Password = try! passText.encrypt(cipher: AES(key: encrypKeyForLogin, iv: ""))

我很困惑,因为在swift 5 iv中16字节可用,但在swift 3 iv=“”之前工作正常。

当它“不工作”时会发生什么?你有错误吗?你是否期望发生一些没有发生的行为?还有别的吗?请编辑您的问题,并添加更多关于您期望发生的事情以及确切发生的事情的详细信息。@HolgerJust。你能解释一下,怎么修吗?谢谢。使用AES时,initvector IV的长度为16字节。某些加密库确实使用(十六进制)x00填充过短的iv。所以,也许斯威夫特3号在这么做,但不是斯威夫特5号。作为解决方案,您应该使用长度16的一些值作为iv,它将起作用。安全警告:静态iv使完整加密不安全!。
Fatal error: 'try!' expression unexpectedly raised an error: CryptoSwift.CBC.Error.invalidInitializationVector: file /Users/vietnguyen/Documents/Mac os/Code/Swift5/SlideOutMenu/SlideOutMenu/Login/LoginServer.swift, line 97 
2020-09-17 21:48:13.326595+0700 SlideOutMenu[2104:103521] Fatal error: 'try!' expression unexpectedly raised an error: CryptoSwift.CBC.Error.invalidInitializationVector: file /Users/vietnguyen/Documents/Mac os/Code/Swift 5/SlideOutMenu/SlideOutMenu/Login/LoginServer.swift, line 97

Line 97: let encryptedBase64Password = try! passText.encrypt(cipher: AES(key: encrypKeyForLogin, iv: ""))