乙個輕量級iOS安全框架 SSKeyChain

2022-09-02 05:51:10 字數 1780 閱讀 7482

摘要

sskeychains對蘋果安全框架api進行了簡單封裝,支援對儲存在鑰匙串中密碼、賬戶進行訪問,包括讀取、刪除和設定。sskeychain的作者是大名鼎鼎的sstoolkit的作者samsoffes。

sskeychain

ios開發

sskeychains對蘋果安全框架api進行了簡單封裝,支援對儲存在鑰匙串中密碼、賬戶進行訪問,包括讀取、刪除和設定。sskeychain的作者是大名鼎鼎的sstoolkit的作者samsoffes。

在工程中加入sskeychain

在工程中加入security.framework框架。

把sskeychain.h和sskeychain.m加到專案資料夾。

使用sskeychain

通過以下類方法來使用sskeychain(請檢視sskeychain.h):

+ (nsarray *)allaccounts;

+ (nsarray *)accountsforservice:(nsstring *)servicename;

+ (nsstring *)passwordforservice:(nsstring *)servicenameaccount:(nsstring *)account;

+ (bool)deletepasswordforservice:(nsstring *)servicenameaccount:(nsstring *)account;

+ (bool)setpassword:(nsstring *)password forservice:(nsstring*)servicename account:(nsstring *)account;

文件在xcode中安裝sskeychain的幫助文件需要以下步驟:

開啟選單 xcode -> preferences

選擇 downloads

選擇 documentation

點選底部的加號按鈕,並輸入以下url:

點選」sskeychain documentation」旁邊的install按鈕。 (如果你看不到它,也沒有提示任何錯誤,請重啟xcode)

確保在organizer中可選的docset中能夠看到sskeychain。

除錯如果無法儲存鑰匙串,請使用sskeychain.h中提供的錯誤**,例如:

nserror *error = nil;

nsstring *password = [sskeychainpasswordforservice:@"myservice" account:@"samsoffes"error:&error]; 

if ([error code] == sskeychainerrornotfound)

顯然,你對做這個應該很熟悉了。訪問鑰匙串是件痛苦的事情,你要隨時檢查它的每個錯誤和失敗。sskeychain並沒有使它(鑰匙串)變得更穩定,它僅僅是繁瑣的c apis封裝。

示例**

儲存乙個uuid字串到鑰匙串:

cfuuidref uuid = cfuuidcreate(null);

assert(uuid != null);

cfstringref uuidstr = cfuuidcreatestring(null, uuid);

[sskeychain setpassword: [nsstring stringwithformat:@"%@", uuidstr]

然後,從鑰匙串讀取uuid:

注意: setpassword和passwordforsevice方法中的services 和 accounts 引數應該是一致的。

乙個輕量級的分頁框架例項

以前部落格上 過乙個師哥的部落格,是關於ssh分頁的,關於分頁的實現大家都有自己用的最順手的方法,但是其實分頁的思想是相似的。感覺師兄的那個方法太 重 了。其實乙個分頁的工具沒必要再細分成那麼多層,這樣顯得太笨重了。下面推薦乙個輕量級的方法,小巧易用,不管是純粹jsp,還是ssh,均可以使用。廢話不...

推薦乙個ruby輕量級MVC框架 Sinatra

sinatra的廣告打的不錯!乙個簡單的hello world,用sinatra只需5行 require rubygems require sinatra get do hello world end果斷測試了一下,一切都很順利。看風格很像python的web.py框架,懷著很好奇的心態,繼續看了下...

peewee 乙個輕量級的ORM 四

class database last insert id cursor,model parameters return type 最後乙個插入的記錄的那行的主鍵,不一定非得叫 id rows affected cursor return type 受影響的行數 create table model...