如何在iOS AWS开发工具包中执行客户端加密? [英] How to perform Client Side Encryption in iOS AWS SDK?

查看:186
本文介绍了如何在iOS AWS开发工具包中执行客户端加密?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可用吗?还是应该选择自己的算法来加密数据并将其上传到S3存储桶?我需要在多平台(android / C#/ ios)中创建一个应用程序,在该应用程序中,我们必须加密数据并将其存储到服务器端。 。 。

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 . . .

我已经尝试过库用于加密数据,但是在iOS方面,我得到的结果与其他人不同。 。 。

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

推荐答案

我使用以下代码通过客户端加密在aws s3存储桶上上传了一个视频。在AWS上上传内容时,我们需要AES256密钥和md5密钥。
首先,添加pod CryptoSwift

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 .

现在生成AES256&

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)
    }

现在在您的aws上传请求中添加以下两行。

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

uploadRequest?.sseCustomerKey =您的AES 256键的base64字符串
uploadRequest?.sseCustomerKeyMD5 =您的md5的base64字符串

这篇关于如何在iOS AWS开发工具包中执行客户端加密?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆