加密 解密

来源:互联网 发布:软件外包项目管理制度 编辑:程序博客网 时间:2024/05/16 19:18

#import "ViewController.h"



#import "RSAEncryptor.h"

@interface ViewController ()


@end


@implementation ViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    NSString * str=@"hello123很好*";

    //创建RSA对象

    RSAEncryptor *rsa = [[RSAEncryptoralloc] init];

    //获取公钥路径

   NSString *publicKeyPath = [[NSBundlemainBundle] pathForResource:@"public_key"ofType:@"der"];;

    [rsaloadPublicKeyFromFile:publicKeyPath];

    //开始加密

   NSString *encryptedString = [rsa rsaEncryptString:str];

   NSLog(@"加密后的结果: %@", encryptedString);

    //获取私钥路径

    [rsa loadPrivateKeyFromFile:[[NSBundlemainBundle] pathForResource:@"private_key"ofType:@"p12"]password:@"123456"];

    //开始解密

   NSString *decryptedString = [rsa rsaDecryptString:encryptedString];

   NSLog(@"解密结果: %@", decryptedString);

}

0 0
原创粉丝点击