我用RSA的public key来解密,php那边用private key来加密,用的Security.framework来解密。但是解出来的数据前面多了一小串奇怪的乱码,后面数据是正确的。谁能帮我看看哪里有问题?
- (NSData *)decryptToDataWithPublicKey: (NSData *)dataToDecrypt { NSData *wrappedSymmetricKey = dataToDecrypt; SecKeyRef key = self.publicKey;//这是之前已经成功使用的SecKeyRef size_t cipherBufferSize = SecKeyGetBlockSize(key); size_t keyBufferSize = [wrappedSymmetricKey length]; NSMutableData *bits = [NSMutableData dataWithLength:keyBufferSize]; __unused OSStatus sanityCheck = SecKeyDecrypt(key, kSecPaddingNone, (const uint8_t *) [wrappedSymmetricKey bytes], cipherBufferSize, [bits mutableBytes], &keyBufferSize); [bits setLength:keyBufferSize]; return [bits copy]; }
最后的数据前面多了一堆fffff,不知道哪里出了问题..
f结束后的数据是正确的。
Ask and answer your own questions. In the end, this method still did not find a solution, and was finally abandoned. Instead, we used the feature of OC to be compatible with C, poured it into the openssl framework, and used openssl functions to decrypt.
Security.framework
Have you noticed the Chinese garbled characters in openssl RSA encryption? Chinese base64 encoding doesn’t work either