How to perform Client Side Encryption in iOS AWS SDK?

三世轮回 提交于 2020-01-07 02:31:28

问题


is it Available ? or should I choose my own algorithm to encrypt data and upload it to the S3-bucket? I'm having a requirement to create an application in multiplatform(android/C#/ios) in which we have to encrypt data and Store it to the server side . . .

I've tried this library to encrypt data, but in iOS side, I'm having different results than others . . .


回答1:


I uploaded a video on aws s3 bucket with client side encryption using below code. We need the AES256 key and md5 key when going to upload content on aws. First, add pod CryptoSwift .

Now generate the AES256 & md5 key from below code.

    let input: Array<UInt8> = [0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9]

    let key: Array<UInt8> = [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]

    let iv: Array<UInt8> = AES.randomIV(AES.blockSize)

    do {
        let encrypted = try AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7()).encrypt(input)
        let base64String: String = encrypted.toBase64()!
        let md5Data = encrypted.md5()
        let md5DataBase64 = md5Data.toBase64()
        print("Encrypted:\(encrypted),\n Base64String:\(base64String)")
        print("md5:\(md5Data),\n md5String:\(md5DataBase64)")

    } catch {
        print(error)
    }

Now add below two lines in your upload request of aws.

uploadRequest?.sseCustomerKey = "Your base64 string of AES 256 key" uploadRequest?.sseCustomerKeyMD5 = "Your base64 string of md5"



来源:https://stackoverflow.com/questions/42434472/how-to-perform-client-side-encryption-in-ios-aws-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!