iOS常用加密方法(aes md5 base64)

2021-06-11 19:36:33 字數 2106 閱讀 2992

ios常用加密方法(aes、md5、base64)

nsdata+aes.h檔案

//

// nsdata-aes.h

// smile

//// created by 周 敏 on 12-11-24.

//#import @class nsstring;

@inte***ce nsdata (encryption)

- (nsdata *)aes256encryptwithkey:(nsstring *)key; //加密

- (nsdata *)aes256decryptwithkey:(nsstring *)key; //解密

@end

nsdata+aes.m檔案

//

// nsdata-aes.h

// smile

//// created by 周 敏 on 12-11-24.

//#import "nsdata+aes.h"

#import @implementation nsdata (encryption)

- (nsdata *)aes256encryptwithkey:(nsstring *)key

free(buffer);

return nil;

}- (nsdata *)aes256decryptwithkey:(nsstring *)key

free(buffer);

return nil;

}@end

這裡aes在ios加過密以後以nsdata的形式存下來,如果想以nsstring形式儲存,那麼對nsdata進行base64位編碼。

g***efines.h

gtmbase64.h

gtmbase64.m

你可以在這裡找到這三個檔案

你也可以在下面的demo裡面找到這3個檔案,demo會完整實現文章裡面常用的3種編碼方法。

我在此稍微封裝一下:

.h檔案

#pragma mark - base64

+ (nsstring*)encodebase64string:(nsstring *)input;

+ (nsstring*)decodebase64string:(nsstring *)input;

+ (nsstring*)encodebase64data:(nsdata *)data;

+ (nsstring*)decodebase64data:(nsdata *)data;

.m檔案

#pragma mark - base64

+ (nsstring*)encodebase64string:(nsstring * )input

+ (nsstring*)decodebase64string:(nsstring * )input

+ (nsstring*)encodebase64data:(nsdata *)data

+ (nsstring*)decodebase64data:(nsdata *)data

nsstring+md5.h檔案

//

// nsstring+md5encrypt.h

// smile

//// created by 周 敏 on 12-11-24.

//#import @inte***ce nsstring (md5)

- (nsstring *)md5encrypt;

@end

nsstring+md5.m檔案

//

// nsstring+md5encrypt.h

// smile

//// created by 周 敏 on 12-11-24.

//#import "nsstring+md5.h"

@implementation nsstring (md5)

- (nsstring *)md5encrypt

@end

加密那些事AES MD5

在開發中,為了安全性考慮,我們常常會用到加密,加密的格式很多,今天我就來簡單寫寫aes md5加密。aes加密 下面是工具類 public class aesutils 解密 param data return throws exception public static string decryp...

iOS常用加密方法(aes md5 base64)

該文原文發表於 ios常用加密方法 aes md5 base64 nsdata aes.h檔案 plain view plain copy nsdata aes.h smile created by 周 敏 on 12 11 24.import class nsstring inte ce nsda...

iOS常用加密方法(aes md5 base64)

nsdata aes.h檔案 nsdata aes.h smile created by 周 敏 on 12 11 24.import class nsstring inte ce nsdata encryption nsdata aes256encryptwithkey nsstring key ...