本文介绍了如何从公钥的指数和模数创建SeckeyRef,并在SecKeyEncrypt方法中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人请帮助创建 SecKeyRef 从指数和模数为我的公众指数 = 010001
公共模数 = 008903fb6d15f352ed3b45add3216f632f7139954a5631337aba7d645ed38482e3a810b4db26aab4d1df58c147230f0c75631a3dd0554b50de44e79f4fcf205c89fd3f80e0ff8d16c2e9f56ed3ab177953d54c9c30357d04e677cedd9912906ef8a046d7b0185b7f2022a8e435b0c6ecaef93f089fc3aa3f3677550b5d842046c7 ,我想用这个SecKeyEncrypt公钥

解决方案

解决问题 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 decoding failed);

NSData * testData2 = [testArray2 berData];
NSLog(@PublicKeyData using Publickeyitems =%@,testData2);
return testData2;
}
- (NSData *)stringasdata:(NSString *)命令{
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 (i = 0; 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:& full_byte length:1];
}
// [commandToSend setLength:[commandToSend length] -1];
return commandToSend;

}


Anyone please help in Creating SecKeyRef from Exponent and Modulus being my Public exponent = 010001and Public Modulus =008903fb6d15f352ed3b45add3216f632f7139954a5631337aba7d645ed38482e3a810b4db26aab4d1df58c147230f0c75631a3dd0554b50de44e79f4fcf205c89fd3f80e0ff8d16c2e9f56ed3ab177953d54c9c30357d04e677cedd9912906ef8a046d7b0185b7f2022a8e435b0c6ecaef93f089fc3aa3f3677550b5d842046c7 and i want to use this SecKeyEncrypt as public key

解决方案

solved the problem NSData *publicTag=[self PublicKeyItems]; in Generating keypair and calling the method
try importing BasicEncodingRules.h and .m in your file

- (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;

}

这篇关于如何从公钥的指数和模数创建SeckeyRef,并在SecKeyEncrypt方法中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-11 17:54