一、RSA加密使用服務端給的公鑰.pem,RSA簽名使用客戶端的私鑰.pem。this
參考文章:http://www.jianshu.com/p/4580bee4f62f加密
把文件夾導入項目中,而後配置這兩個地方就OK了,若是是新建項目記得關閉Bitcode.spa
關鍵代碼code
HBRSAHandler* handler = [HBRSAHandler new]; //加密
NSString *PublicFilePath = [[NSBundle mainBundle] pathForResource:@"serverPubKey.pem" ofType:nil]; [handler importKeyWithType:KeyTypePublic andPath:PublicFilePath];//加載公鑰
NSString *test = @"須要加密的數據"; test = [handler encryptWithPublicKey:test]; NSLog(@"加密結果 =%@",test); //簽名
NSString *privateKeyFilePath = [[NSBundle mainBundle] pathForResource:@"clientPriKey.pem" ofType:nil]; [handler importKeyWithType:KeyTypePrivate andPath:privateKeyFilePath];//加載私鑰
NSString *xml = @"this is test message!"; xml = [handler signString:xml]; NSLog(@"簽名結果:%@",xml);
公鑰和私鑰都是字符串,用字符串加密也能夠。server
Dem下載 密碼:4bpwxml