superk589 / RijndaelSwift

A simple Rijndael implementation in Swift
MIT License
10 stars 2 forks source link

Issue While JSON Parsing after decryption #3

Closed dollykosmos closed 5 years ago

dollykosmos commented 5 years ago

How to remove PKCS#5 padding in last from decrypted string

superk589 commented 5 years ago

By now, this library does not support PKCS#5 padding.

superk589 commented 5 years ago

You can try this lines from CryptoSwift


    func remove(from bytes: Array<UInt8>, blockSize _: Int?) -> Array<UInt8> {
        guard !bytes.isEmpty, let lastByte = bytes.last else {
            return bytes
        }

        assert(!bytes.isEmpty, "Need bytes to remove padding")

        let padding = Int(lastByte) // last byte
        let finalLength = bytes.count - padding

        if finalLength < 0 {
            return bytes
        }

        if padding >= 1 {
            return Array(bytes[0..<finalLength])
        }
        return bytes
    }
dollykosmos commented 5 years ago

Thanks for the update. I am using CryptoSwift only for now. My issue resolved.