ideawu / Objective-C-RSA

Doing RSA encryption and decryption with Objective-C on iOS
http://www.ideawu.com/blog/post/132.html
Other
1.15k stars 280 forks source link

Public Key #2

Open ddaddy opened 9 years ago

ddaddy commented 9 years ago

Hi, I have a key from Java that looks like OpenSSLRSAPublicKey{modulus=3b11f044.....58df890,publicExponent=10001}

Do I just use the modulus string as the public key or would I need to somehow convert this whole key to another format to use?

Thanks

ddaddy commented 9 years ago

I think i've managed to get a base64 encoded key from java now, however this code now pauses on line 108 - OSStatus status = SecItemAdd((__bridge CFDictionaryRef)publicKey, &persistKey); And when I click continue in the debugger it carries on as normal however the encoded string is NULL.

Is there an issue when trying with a new key? It's not crashing, just pausing.

ddaddy commented 9 years ago

Ok, sorry about so many notes. It seems it's pausing with an Exception, as if I remove the exception breakpoint it runs just fine, however the encoded string is always NULL :(

ideawu commented 9 years ago

Is the public key string in the format of this form?

-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDEChqe80lJLTTkJD3X3Lyd7Fj+
zuOhDZkjuLNPog3YR20e5JcrdqI9IFzNbACY/GQVhbnbvBqYgyql8DfPCGXpn0+X
NSxELIUw9Vh32QuhGNr3/TBpechrVeVpFPLwyaYNEk1CawgHCeQqf5uaqiaoBDOT
qeox88Lc1ld7MsfggQIDAQAB
-----END PUBLIC KEY-----
ddaddy commented 9 years ago

Yes, I can get it working fine if I setup a new iOS project. I was originally using an OSX project. I wonder if it's an issue to do with code signing as I don't have a valid OSX dev membership but do for iOS. For it to use the keychain would it require proper code signing?

cheizer commented 9 years ago

I have an OS X CLI project and i'm having the same issue.

108 - OSStatus status = SecItemAdd((__bridge CFDictionaryRef)publicKey, &persistKey); OSStatus = -25303 and return NULL encoded string.

The persistKey appears to be nil after the SecItemAdd.

tomguan commented 9 years ago

Hello. I wander how to encrype RSA by two parameters, "Mod“, ”Exp" ?

winwys commented 9 years ago

iOS9 no worked。。。help

btnguyen2k commented 8 years ago

@tomguan this link might help http://www.scriptscoop.com/t/b7214526ca56/ios-create-seckey-from-modulus-and-exponent-in-swift.html