iPhoneでメッセージを暗号化したい。私はモジュラスと指数を持っています。私が参照しているコード
公開鍵の指数と係数から SeckeyRef を作成し、SecKeyEncrypt メソッドで使用する方法
+(NSString *)encryptRSA:(NSString *)plainTextString key:(NSString *)key
{
NSString *publicKeyIdentifier = [NSString stringWithFormat:@"%@.publickey",[[NSBundle mainBundle] bundleIdentifier]];
[Crypto setPublicKey:key tag:(NSString *)publicKeyIdentifier];
SecKeyRef publicKey = NULL;
NSData * publicTag = [self PublicKeyItems/*publicKeyIdentifier dataUsingEncoding:NSUTF8StringEncoding*/];
NSMutableDictionary *queryPublicKey = [[[NSMutableDictionary alloc] init] autorelease];
[queryPublicKey setObject:(id)kSecClassKey forKey:(id)kSecClass];
[queryPublicKey setObject:publicTag forKey:(id)kSecAttrApplicationTag];
[queryPublicKey setObject:(id)kSecAttrKeyTypeRSA forKey:(id)kSecAttrKeyType];
[queryPublicKey setObject:[NSNumber numberWithBool:YES] forKey:(id)kSecReturnRef];
SecItemCopyMatching((CFDictionaryRef)queryPublicKey, (CFTypeRef *)&publicKey);
if (!publicKey)
{
if(publicKey) CFRelease(publicKey);
[Exception raise:FAILURE function:__PRETTY_FUNCTION__ line:__LINE__ description:@"Could not decrypt."];
}
私も BasicEncodingRules.m と .h の両方を使用します。しかし、私には警告があります
+ (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 *testData1 = [testData berDecode];
NSLog(@"testarray = %@",testData1);
STAssertEqualObjects(testData, testData1, @"Big items decode failed");
// warning at this line, with content "Implicit declaration of function STAssertEqualObjects is invalid in C99"
NSData *testData2 = [testData1 berData];
NSLog(@"PublicKeyData using Publickeyitems = %@",testData2);
return testData2;
}
だから私はCrypto.oを構築できません
私を助けてください!とにかくありがとう