Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting " " (empty) Decrypted string from update function #76

Open
nirav-kotecha opened this issue Sep 12, 2022 · 0 comments
Open

Getting " " (empty) Decrypted string from update function #76

nirav-kotecha opened this issue Sep 12, 2022 · 0 comments

Comments

@nirav-kotecha
Copy link

nirav-kotecha commented Sep 12, 2022

class func decrypt(encodedData: String, secret: String, algorithm: String) -> String {
        do {
            let key = Array(secret.utf8)
            let bytes = encodedData.hexaBytes
            let cryptor = try Cryptor(operation:.decrypt, algorithm:.aes256, options:[.ecbMode, .pkcs7Padding], key:key, iv:[UInt8]())
            if let decrypted = cryptor.update(byteArray: bytes)?.final() {
                return String(bytes: decrypted, encoding: .utf8) ?? ""
            }
        } catch {
            print(error)
        }
        return ""
}

i am using above function to decrypt data. it will returning blank "" string.
i am using .ecbMode and .pkcs7Padding pattern
also i am getting key and bytes data successfully. issue in cryptor.update function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant