网络:RSA 加密

来源:互联网 发布:行知职高厨师学费 编辑:程序博客网 时间:2024/06/10 06:53
#import "ViewController.h"#import "CryptorTools.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view, typically from a nib.}- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {    CryptorTools *tool = [[CryptorTools alloc]init];    NSString *privateKey = [[NSBundle mainBundle]pathForResource:@"p.p12" ofType:nil];    NSString *publicKey = [[NSBundle mainBundle]pathForResource:@"rsacert.der" ofType:nil];    // 加载私钥    [tool loadPrivateKey:privateKey password:@"123456"];    // 加载公钥    [tool loadPublicKeyWithFilePath:publicKey];    // 加密   NSString *result = [tool RSAEncryptString:@"itcast"];    NSLog(@"rsa加密结果 %@",result);    // 解密    NSString *result1 = [tool RSADecryptString:result];    NSLog(@"rsa解密结果 %@",result1);}@end
0 0