我正在创建签名,并且在签名的消息长度方面遇到了麻烦。通过遵循Apple iOS(http://apple.co/2ucaOTB)的编码指南,以下代码适用于任何短于223长度的消息,不能超过222.您能告诉我为什么它严格限制在222?< / p>
NSString *dataToSign = @"eyJhbGciOiJSUzUxMiIsImtpZCI6IkFTLVVXUC1DZXJ0LTAxIiwieDVIjoiSmpBZHB3TGt4YVNvWWF0Z2NnaElpZlJ4c3A0In0śhgrphgrpehgersfnrwuiefbgerwighberuyabfgeruykbverkhgerbiuseyJzdWIiOiI2ZjAzNGViZS101MDc4ZDBjZTI0ZjIiLCJlbfasdfdfdfdfdfdqweja";//222 chars.
NSData* data2sign = [dataToSign dataUsingEncoding:NSUTF8StringEncoding];
NSLog(@"Data is %u", data2sign.length);// %u will be 222.
SecKeyAlgorithm algorithm = kSecKeyAlgorithmRSASignatureDigestPSSSHA256;
// privateKey is 2048 bits asymmetric RSA.
BOOL canSign = SecKeyIsAlgorithmSupported(privateKey, kSecKeyOperationTypeSign, algorithm);
if (canSign) {// It is true, and it tries to create signature.
CFErrorRef error = NULL;
signature = (NSData *)CFBridgingRelease(
SecKeyCreateSignature(
privateKey,
algorithm,
(__bridge CFDataRef)data2Sign,
&error));
if (!signature) {
NSError *err = CFBridgingRelease(error);
NSLog(@"The error is: %@", err);
}
NSLog(@"The signature is %@", signature);
}