如何在Objective C中使用AES 256 CBC进行加密 [英] How to encrypt with AES 256 CBC in Objective C
本文介绍了如何在Objective C中使用AES 256 CBC进行加密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在构建一个iPhone应用程序,该应用程序将获取一个加密字符串并将其发送到后端.
I am building an iPhone app which gets a encrypt string and sent it to backend.
在PHP中,我像这样对字符串进行加密:
In PHP I am encrypting the string like this:
$encrypt_method = "AES-256-CBC";
$secret_key = 'This is my secret key';
$secret_iv = 'This is my secret iv';
// hash
$key = hash('sha256', $secret_key);
// iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
$iv = substr(hash('sha256', $secret_iv), 0, 16);
if( $action == 'encrypt' ) {
$output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
$output = base64_encode($output);
}
除了在Objective C中,我该怎么做
How I do the same like that but in Objective C
推荐答案
感谢 Nirav Kotecha .
我最终使用了 CrytoSwift ,并添加了扩展类NSString和String来调用它.
I ended up using CrytoSwift and Add Extension class NSString and String to call it.
这篇关于如何在Objective C中使用AES 256 CBC进行加密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文