久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

iOS 5:數(shù)據(jù)加密 AES-256 EncryptWithKey:未找到

iOS 5: Data encryption AES-256 EncryptWithKey: not found(iOS 5:數(shù)據(jù)加密 AES-256 EncryptWithKey:未找到)
本文介紹了iOS 5:數(shù)據(jù)加密 AES-256 EncryptWithKey:未找到的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時送ChatGPT賬號..

問題是關(guān)于iOS5 應(yīng)用程序.我有一個視圖控制器,其中有一些 UITextFields.我想使用 AES-256 加密數(shù)據(jù).

Question is about iOS5 application. I have a view controller where I have some UITextFields. I would like to encrypt data using AES-256.

事實上,我不知道我必須添加哪些必備包才能進(jìn)行加密和解密.我已經(jīng)瀏覽過其他帖子,但太多的解釋搞砸了.

In fact, I don't know what are the prerequisite packages that I have to add to do encryption and decryption. I have gone trough other posts but too much explanation messed it up.

請告訴我使用 AES-256 加密數(shù)據(jù)時必須包含的所有包和頭文件

Kindly let me know what and all packages, header files I have to include to encrypt data using AES-256

錢德拉

推薦答案

參考以下類別.

常見問題解答:什么是類別?

FAQ: What is a category?

簡而言之,Cocoa API 添加方法.簡要擴(kuò)展類.

In short, Cocoa API to add the method. briefly expand class.

更多信息,

自定義現(xiàn)有類

類別

File-New-Cocoa Touch - Objective-C 類

File-New-Cocoa Touch - Objective-C category

如果你想使用一個類別,你的類添加一個#importNSData+Encryption.h"

If you want to use a category, your class add a #import"NSData+Encryption.h"

//NSData+加密.h

//NSData+Encryption.h

@interface NSData (Encryption)
- (NSData *)AES256EncryptWithKey:(NSString *)key;
- (NSData *)AES256DecryptWithKey:(NSString *)key;
@end


//NSData+Encryption.m


//NSData+Encryption.m

#import "NSData+Encryption.h"
#import <CommonCrypto/CommonCryptor.h>

@implementation NSData (Encryption)
- (NSData *)AES256EncryptWithKey:(NSString *)key {
    // 'key' should be 32 bytes for AES256, will be null-padded otherwise
    char keyPtr[kCCKeySizeAES256+1]; // room for terminator (unused)
    bzero(keyPtr, sizeof(keyPtr)); // fill with zeroes (for padding)
    
    // fetch key data
    [key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
    
    NSUInteger dataLength = [self length];
    
    //See the doc: For block ciphers, the output size will always be less than or 
    //equal to the input size plus the size of one block.
    //That's why we need to add the size of one block here
    size_t bufferSize = dataLength + kCCBlockSizeAES128;
    void *buffer = malloc(bufferSize);
    
    size_t numBytesEncrypted = 0;
    CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt, kCCAlgorithmAES128, kCCOptionPKCS7Padding,
                                          keyPtr, kCCKeySizeAES256,
                                          NULL /* initialization vector (optional) */,
                                          [self bytes], dataLength, /* input */
                                          buffer, bufferSize, /* output */
                                          &numBytesEncrypted);
    if (cryptStatus == kCCSuccess) {
        //the returned NSData takes ownership of the buffer and will free it on deallocation
        return [NSData dataWithBytesNoCopy:buffer length:numBytesEncrypted];
    }
    
    free(buffer); //free the buffer;
    return nil;
}

- (NSData *)AES256DecryptWithKey:(NSString *)key {
    // 'key' should be 32 bytes for AES256, will be null-padded otherwise
    char keyPtr[kCCKeySizeAES256+1]; // room for terminator (unused)
    bzero(keyPtr, sizeof(keyPtr)); // fill with zeroes (for padding)
    
    // fetch key data
    [key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
    
    NSUInteger dataLength = [self length];
    
    //See the doc: For block ciphers, the output size will always be less than or 
    //equal to the input size plus the size of one block.
    //That's why we need to add the size of one block here
    size_t bufferSize = dataLength + kCCBlockSizeAES128;
    void *buffer = malloc(bufferSize);
    
    size_t numBytesDecrypted = 0;
    CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt, kCCAlgorithmAES128, kCCOptionPKCS7Padding,
                                          keyPtr, kCCKeySizeAES256,
                                          NULL /* initialization vector (optional) */,
                                          [self bytes], dataLength, /* input */
                                          buffer, bufferSize, /* output */
                                          &numBytesDecrypted);
    
    if (cryptStatus == kCCSuccess) {
        //the returned NSData takes ownership of the buffer and will free it on deallocation
        return [NSData dataWithBytesNoCopy:buffer length:numBytesDecrypted];
    }
    
    free(buffer); //free the buffer;
    return nil;
}
@end

這篇關(guān)于iOS 5:數(shù)據(jù)加密 AES-256 EncryptWithKey:未找到的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Using Instruments to test an iOS app without having source code to the application(在沒有應(yīng)用程序源代碼的情況下使用 Instruments 測試 iOS 應(yīng)用程序)
KIF: How to auto-run/stress test an iOS app to find the cause of a rare UI bug?(KIF:如何自動運行/壓力測試 iOS 應(yīng)用程序以找出罕見 UI 錯誤的原因?)
Can#39;t change target membership visibility in Xcode 4.5(無法更改 Xcode 4.5 中的目標(biāo)成員身份可見性)
UITableView: Handle cell selection in a mixed cell table view static and dynamic cells(UITableView:在混合單元格表視圖靜態(tài)和動態(tài)單元格中處理單元格選擇)
How to remove Address Bar in Safari in iOS?(如何在 iOS 中刪除 Safari 中的地址欄?)
iOS 5 SDK is gone after upgrade to Xcode 4.5(升級到 Xcode 4.5 后,iOS 5 SDK 消失了)
主站蜘蛛池模板: 97精品超碰一区二区三区 | 韩日在线观看视频 | 成人免费激情视频 | 亚洲日日操 | 成人激情视频网 | 一区二区三区欧美在线 | 欧美区在线观看 | 国产欧美日韩精品一区 | 国产免费va | 九九久久精品 | 999热在线视频 | 国产大学生情侣呻吟视频 | 亚洲成人av一区二区 | av电影一区 | 欧美精品一区在线 | 91看片网| 中文字幕在线观看视频一区 | 国产精品www | 国产精品视频一区二区三区 | 在线视频一区二区三区 | 久久久久九九九九 | 久久国产精品72免费观看 | 欧美精品综合在线 | 黄网站涩免费蜜桃网站 | 久久久精品网站 | www.久| 欧美视频精品 | 国产视频亚洲视频 | av黄色免费在线观看 | 亚洲国产精品一区在线观看 | 国产在线精品免费 | 99精品欧美一区二区三区 | 国产精品乱码一区二区三区 | 成人免费一区二区三区视频网站 | 欧美a区 | 国产视频精品在线观看 | 久久精品一区二区视频 | 亚洲综合色视频在线观看 | 色网站在线免费观看 | 国产在线精品一区二区 | 亚洲久久 |