2015-02-11 38 views
0

您好我有使用MIHCrypto v0.3.2解密的问题。这是我的代码行:使用MIHCrypto解密RSA(OpenSSL-Universal在iOS上)

NSString *encrypted_text = @"BdhFH0sd7e9DExiCd50Ykh4spm2BX126skjJ1o8HHjKsN+J7r9IoI9kbB9AAacEpJsAfyesiJsq5gDBhQtcNbB6l88aSgPrEoVwR9ilzuzVcv1q3J1dxs4uIEMuhzoWT+R8//dD2jDdXPyFsdGWJc10CEizPFKpmy2jWhvU8CVs="; 
NSBundle *myBundle = [NSBundle mainBundle]; 
NSString *privateKeyPath= [myBundle pathForResource:@"rsa_1024_priv" ofType:@"pem"];  
NSData *privateKeyData = [[NSFileManager defaultManager] contentsAtPath:privateKeyPath]; 
MIHRSAPrivateKey *privateKey = [[MIHRSAPrivateKey alloc] initWithData:privateKeyData]; 
NSError *decryptionError = nil; 

// decryption 
NSData *encData = [encrypted_text dataUsingEncoding:NSUTF8StringEncoding]; 
NSData *decryptedEncData = [privateKey decrypt:encData error:&decryptionError]; 
NSString* decryptedText = [[NSString alloc] initWithData:decryptedEncData encoding:NSUTF8StringEncoding]; // iOS 7+, by iOS Core API 

if(decryptionError){ 
    DDLogDebug(@"error: %@",[encryptionError localizedDescription]); 
} 
DDLogDebug(@"decrypted: %@",decryptedEncData); 

的问题在这里调试:

错误:OpenSLL内部错误! (代码= 67522668,说明=错误:0406506C:rsa例程:RSA_EAY_PRIVATE_DECRYPT:数据大于mod len)

您有任何想法吗?

回答

0

我终于找到了一个解决方案:

使用较短的数据块!

背景(张贴由Hohl - here):

Using RSA with large blocks of data seems to be a common issue. Some wrappers handle this by splitting the data into smaller blocks and encrypting every block separately. But since RSA isn't intended to encrypt large blocks of data this won't be implemented in this wrapper. (Better combine RSA with something like AES if you need features of both worlds.)