gpt4 book ai didi

swift - CryptLib 解密返回错误值

转载 作者:搜寻专家 更新时间:2023-11-01 05:34:27 25 4
gpt4 key购买 nike

我正在使用 Cross-Platform-AES用于我的 swift 应用程序中的 AES 加密/解密。我的加密工作正常。但是当我尝试解密服务返回值时,它没有给我正确的结果。这是我解密的方式。

public func decryptStrings(text:String)->String{

let hashKey=cryptoLib.sha256(key, length: 31)
let decryptedData = cryptoLib.decrypt(text.data(using: String.Encoding.utf8), key: hashKey, iv: iv)
let decryptedString=decryptedData?.base64EncodedString()
print("decryptedString \(decryptedString! as String)")
return decryptedString!

}

请向我解释如何以正确的方式解密它。谢谢

加密

public func base64Convertion (secretcode:String)->String
{


let hashKey=cryptoLib.sha256(key, length: 31)
let encryptedData=cryptoLib.encrypt(secretcode.data(using: String.Encoding.utf8), key: hashKey, iv: iv)
let encryptedString=encryptedData?.base64EncodedString()
print("encryptedString \(encryptedString! as String)")


return encryptedString!

}

最佳答案

我通过这种方式更改解密方法解决了问题

    public func decryptStrings(text:String)->String{

let hashKey=cryptoLib.sha256(key, length: 31)
let decodedData = Data(base64Encoded: text, options: Data.Base64DecodingOptions())
let decryptedData = cryptoLib.decrypt(decodedData, key: hashKey, iv: iv)
let decryptedString=String(data: decryptedData!,encoding:String.Encoding.utf8)
print("decryptedString \(decryptedString!)")
return decryptedString!

}

关于swift - CryptLib 解密返回错误值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44258550/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com