iphone - 如何根据公钥的指数和模数创建 SeckeyRef 并在 SecKeyEncrypt 方法中使用

标签 iphone encryption rsa public-key-encryption

任何人请帮助从指数和模数创建SecKeyRef作为我的公共(public)指数 = 010001公共(public)模数 =008903fb6d15f352ed3b45add3216f632f7139954a5631337aba7d645ed38482e3a810b4db26aab4d1df58c147230f0c75631a3dd0554b50de44 e79f4fcf205c89fd3f80e0ff8d16c2e9f56ed3ab177953d54c9c30357d04e677cedd9912906ef8a046d7b0185b7f2022a8e435b0c6ecaef93f089fc3aa3f3677550b 5d842046c7 我想使用这个 SecKeyEncrypt 作为公钥

最佳答案

解决了生成 key 对并调用方法中的问题NSData *publicTag=[self PublicKeyItems];
尝试在您的文件中导入 BasicEncodingRules.h 和 .m

- (NSData *)PublicKeyItems
{
NSString *exp = @"010001";
NSLog(@"Publickeyexp -%@",exp);
NSData *publickeyexpdata= [self stringasdata:exp];
NSLog(@"publickeyexpdata = %@",publickeyexpdata);
NSString *mod = @"008903fb6d15f352ed3b45add3216f632f7139954a5631337aba7d645ed38482e3a810b4db26aab4d1df58c147230f0c75631a3dd0554b50de44e79f4fcf205c89fd3f80e0ff8d16c2e9f56ed3ab177953d54c9c30357d04e677cedd9912906ef8a046d7b0185b7f2022a8e435b0c6ecaef93f089fc3aa3f3677550b5d842046c7";
NSLog(@"Publickeymod -%@",mod);
NSData *publickeymoddata= [self stringasdata:mod];
NSLog(@"publickeymod = %@",publickeyexpdata);

NSMutableArray *publicarray = [[NSMutableArray alloc] init];
[publicarray addObject:publickeyexpdata];
[publicarray addObject:publickeymoddata];
NSData *testData = [publicarray berData];
NSLog(@"testdata = %@",testData);
NSMutableArray *testArray2 = [testData berDecode];
NSLog(@"testarray = %@",testArray2);
//STAssertEqualObjects(testArray, testArray2,
                    // @"Big items decode failed");

NSData *testData2 = [testArray2 berData];
 NSLog(@"PublicKeyData using Publickeyitems = %@",testData2);
return testData2;
}
-(NSData *)stringasdata:(NSString *)command {
command = [command stringByReplacingOccurrencesOfString:@" " withString:@""];
command = [command stringByReplacingOccurrencesOfString:@"<" withString:@""];
command = [command stringByReplacingOccurrencesOfString:@">" withString:@""];
NSLog(@"command= %@",command);
NSMutableData *commandToSend= [[NSMutableData alloc] init]; unsigned char whole_byte;
int len = [command length];
int n = len/2;
char byte_chars[3] = {'\0','\0','\0'}; int i;
for (i=0; i < n; i++) {
    byte_chars[0] = [command characterAtIndex:i*2]; byte_chars[1] = [command         characterAtIndex:i*2+1]; whole_byte = strtol(byte_chars, NULL, 16); [commandToSend appendBytes:&whole_byte length:1];
}
// [commandToSend setLength:[commandToSend length]-1];
return commandToSend; 

}

关于iphone - 如何根据公钥的指数和模数创建 SeckeyRef 并在 SecKeyEncrypt 方法中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11516355/

相关文章:

iphone - 从 Plist 登录检查凭据

iphone - 当 iPad 方向改变时,UIView 动画行为异常

java - 使用PBKDF2 java解密和加密

java MD5加密减去字节数组中的值

Iphone - 如何使用公钥加密 NSData 并使用私钥解密?

amazon-web-services - 将 pem 私有(private) key 添加到 AWS KMS

java - 在 Ruby 中加密的字符串给出 : 'BadPaddingException' when decrypted in Java

ios - 在 MKUserTrackingModeFollowWithHeading map 模式下设置 MKMapCamera 时奇怪的 MKMapView 行为

java - 将 Base64 编码的 CER 文件保存到字符串

ios - 使用 Alamofire 解析字典中的 json 对象