我使用SecKeyEncryptJSON格式的字符串作为输入.如果传递SecKeyEncrypt一个小于246的plainTextLength,它就可以工作.如果我传给它的长度为246或更长,则失败并返回值:paramErr (-50).
它可能是字符串本身的问题.我可能发送的一个例子SecKeyEncrypt是:
{"handle":"music-list","sym_key":"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALeaEO7ZrjgOFGLBzBHZtQuzH2GNDYMLWP+fIFNu5Y+59C6HECY+jt0yOXXom2mzp/WYYI/9G+Ig8OD6YiKv2nMCAwEAAQ==","app_id":"xgfdt.LibraryTestApp","api_key":"7e080f74de3625b90dd293fc8be560a5cdfafc08"}
第245个字符为'0'.
在此工作之间切换的唯一输入是plainTextLength.SecKeyGetBlockSize()正在向我返回256,所以任何长达256个字符的输入都应该有效.
这是我的加密方法:
+ (NSData*)encrypt:(NSString*)data usingPublicKeyWithTag:(NSString*)tag
{
OSStatus status = noErr;
size_t cipherBufferSize;
uint8_t *cipherBuffer;
// [cipherBufferSize]
size_t dataSize = 246;//[data lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
const uint8_t* textData = [[data dataUsingEncoding:NSUTF8StringEncoding] bytes];
SecKeyRef publicKey = [Encryption copyPublicKeyForTag:tag];
NSAssert(publicKey, @"The public key being referenced by tag must have been stored in the keychain before attempting to encrypt data using it!");
// Allocate a buffer
cipherBufferSize = SecKeyGetBlockSize(publicKey);
// this value … 用一个简单的例子可以很容易地解释这一点.假设我有以下协议和类定义:
@protocol ProtocolA <NSObject>
@optional
+ (BOOL)methodA;
@end
@interface ClassA : NSObject <ProtocolA>
@end
Run Code Online (Sandbox Code Playgroud)
ClassA可能会也可能不会定义methodA.如果我正在使用实例ClassA和实例方法的实例,我可以使用respondsToSelector:.然而,在这种情况下,我想不出任何干净的方法来确定是否ClassA定义(响应)methodA.
编辑: 我很傻,并没有让我的例子足够详细,这意味着问题的答案并不完全是我的问题的解决方案 - 所以我包括更多的代码和我得到的警告:
Class <ProtocolA> classRef = [ClassA class];
if([classRef respondsToSelector:@selector(methodA)]) {}
Run Code Online (Sandbox Code Playgroud)
上面的代码抛出以下警告:" respondsToSelector:找到实例方法' 而不是类方法' respondsToSelector:'"
我刚刚注意到,如果我明确地施展classRef,(Class)那么警告就会消失.我仍觉得奇怪.
我有很多NSString,看起来像这样:
@"this is the content. The content of this string may vary, as well as the length, and my include any characters, with numbers Y = 295.000000 X = 207.500000"
Run Code Online (Sandbox Code Playgroud)
除了可能改变的X和Y数之外,Y = 295.000000 X = 207.500000的部分总是相同的.
我需要以某种方式获取这些数字并执行以下操作:
coordsFinal.x = 295.000000;
coordsFinal.y = 207.500000;
Run Code Online (Sandbox Code Playgroud)
其格式为:
coordsFinal.x = [NSString stringWithFormat: @"%@", trimmed string];
Run Code Online (Sandbox Code Playgroud)
有任何想法吗??