ios開發過程中的相關加密演算法

2021-07-04 18:33:31 字數 3421 閱讀 1418

自己試一下吧 常見的md5 sha1 base64 等常見的演算法均有 後續有信的研究再做擴充

[objc]view plain

copy

////  nsstring+help.h

////  created by mac10.9.4 on 14-9-21.

//#import 

#import 

@inte***ce

nsstring (help)  

/*** 命令列測試命令

**  md5

*  $ echo -n abc | openssl md5

*  sha1

*  $ echo -n abc | openssl sha1

*  sha256

*  $ echo -n abc | openssl sha -sha256

*  sha512

*  $ echo -n abc | openssl sha -sha512

*  base64編碼(abc)

*  $ echo -n abc | base64

**  base64解碼(ywjj,abc的編碼)

*  $ echo -n ywjj | base64 -d

*//**

*  返回md5加密後的字串

*/@property

(nonatomic

, readonly

) nsstring

*md5

string;  

/***  返回sha1遍嗎後的字串

*/@property

(nonatomic

, readonly

) nsstring

*sha

1string;  

/***  返回sha256遍嗎後的字串

*/@property

(nonatomic

, readonly

) nsstring

*sha25

6string;  

/***  返回sha512遍嗎後的字串

*/@property

(nonatomic

, readonly

) nsstring

*sha51

2string;  

/***  返回base64遍嗎後的字串

*/@property

(nonatomic

, readonly

) nsstring

*base64

encode;  

/***  返回base64解碼後的字串

*/@property

(nonatomic

, readonly

) nsstring

*base64

decode;  

/***  計算一行字的size

**  @param fount fount

**  @return 計算好的 size

*/- (cgsize)sizewithstingfount:(uifont

*)fount;  

/***  計算字串的size

**  @param fount   fount

*  @param maxsize 字串可以佔據的最大的size

**  @return size

**  @exception 計算好的 size

*/- (cgsize)sizewithstingfount:(uifont

*)fount

withmaxsize

:(cgsize)maxsize;  

@end

[objc]view plain

copy

//  nsstring+help.m

////  created by mac10.9.4 on 14-9-21.

//#import "nsstring+help.h"

#import 

@implementation

nsstring (help)  

/***  返回md5加密後的字串

*/- (nsstring

*)md

5string  

/***  返回sha1遍嗎後的字串

*/- (nsstring

*)sha

1string  

/***  返回sha256遍嗎後的字串

*/- (nsstring

*)sha25

6string  

/***  返回sha512遍嗎後的字串

*/- (nsstring

*)sha51

2string  

- (nsstring

*)stringfrombytes:(unsigned 

char

char

*)bytes

length

:(int

)length  

return

[strm

copy

];  

}  /**

*  返回base64遍嗎後的字串

*/- (nsstring

*)base64

encode   

/***  返回base64解碼後的字串

*/- (nsstring

*)base64

decode   

/***  計算一行字的size

**  @param fount fount

**  @return 計算好的 size

*/- (cgsize)sizewithstingfount:(uifont

*)fount  

/***  計算字串的size

**  @param fount   fount

*  @param maxsize 字串可以佔據的最大的size

**  @return size

**  @exception 計算好的 size

*/- (cgsize)sizewithstingfount:(uifont

*)fount

withmaxsize

:(cgsize)maxsize;  

;  return

[self

boundingrectwithsize

:maxsize

options

:nsstringdrawinguseslinefragmentorigin

attributes

:attrs

context

:nil

].size

;  }  

@end

ios開發過程中的相關加密演算法

自己試一下吧 常見的md5 sha1 base64 等常見的演算法均有 後續有信的研究再做擴充 nsstring help.h created by mac10.9.4 on 14 9 21.import import inte ce nsstring help 命令列測試命令 md5 echo n...

iOS開發過程中,NSLog巨集定義

在專案開發的過程中,經常遇到要在除錯的時候列印log,但是上線或是release 的時候不需要去顯示log 的情況,此時你辛辛苦苦寫了那麼多的log,你要麼就手動注釋掉,要麼就是設乙個開關變數,企圖用這個總開關開啟。其實可以充分利用巨集定義進行設定。步驟比較簡單,只需要 在projectname p...

iOS開發過程中遇到的小問題

1.xcode6.1建立繼承自nsobject類的資料模型,如果需要加關於ui的屬性時需要加入uikit的標頭檔案。3.xocde6 官方的小bug,用storyboard建立的工程在4寸屏上執行時會出現上下黑條的現象,此時需要加乙個啟 方可解決此問題。4.設定view的偏移量 self.view....