开发者

How to use initWithModulus function in MyCrypto library?

I use MyCrypto library for a IPhone app. The program will comunicate with a web service that is writen by WCF.The service will provide a public key by providing modulus and exponent. Thus, we need use initWithModulus to create a public key. The code is as following.

MYPrivateKey *pair = [[MYKeychain defaultKeychain] generateRSAKeyPairOfSize: 2048];
MYPublicKey *pub = pair.publicKey;
NSData * outModulus;
unsigned outExponent;
[pub getModulus:&outModulus exponent:&outExponent]; 
MYPublicKey *serverKey = [[MYPublicKey alloc] initWithModulus: outModulus exponent: outExponent]; 
NSString *tmpStr = @"test!"; 
NSData *tmpData = [tmpStr dataUsingEncoding: NSASCIIStringEncoding]; 
NSData *crypted = [serverKey rawEncryptData: tmpData]; 
NSData *crypted2 = [pub rawEncryptData: tmpData]; 

For test, I use initWithModulus to create a publickey. Then the same data are encrypted with 开发者_开发问答the original key and the new one. But the lengths of the two encrypted data are different. How shoud I do?


What are the mismatched lengths? When I run this code (in the iOS 4 simulator) it works, and the length of the encrypted data is 256 bytes.

If you try encrypting with the original private key and then decrypting with the reconstituted public key, does that work?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜