久久久久久久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ī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 添加方法.簡要擴展類.

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 消失了)
主站蜘蛛池模板: 久国产精品 | 成人片免费看 | 美女黄网 | www.青青草 | 亚洲九九 | 色婷婷综合久久久中字幕精品久久 | 日韩一区二区在线视频 | 日韩a| 久久一二区 | 国产精品视频免费 | 91中文字幕 | 91精品国产91久久久久久吃药 | 亚洲一区二区三区四区五区午夜 | 免费v片 | 日本精品一区二区三区视频 | 亚洲综合日韩精品欧美综合区 | 人人鲁人人莫人人爱精品 | 欧美视频精品 | 日韩成人精品一区二区三区 | 久久精品视频免费看 | 国产偷录叫床高潮录音 | 日韩靠逼| 精品欧美一区二区中文字幕视频 | 五月婷婷婷 | 国产不卡一区 | 国产精品久久 | 麻豆一区 | 亚洲综合日韩精品欧美综合区 | 亚洲狠狠 | 国产一区三区在线 | 日韩精品一区二区三区在线观看 | 成人在线视频网站 | 国产精品毛片一区二区三区 | 精品视频99 | 午夜久久久 | 日韩高清一区二区 | 亚洲视频在线观看 | 做a的各种视频 | 99国产精品久久久久久久 | 中文字幕在线观看第一页 | 国产精品久久久久久久久久久久久 |