Re: SecKeyRef object without KeyChain [issues with kSecPkcs1Padding]
Re: SecKeyRef object without KeyChain [issues with kSecPkcs1Padding]
- Subject: Re: SecKeyRef object without KeyChain [issues with kSecPkcs1Padding]
- From: "email@hidden" <email@hidden>
- Date: Sun, 11 Sep 2011 09:20:02 +0100
On 11 Sep 2011, at 03:46, Shivani Bansal wrote:
> Hi,
> I debugged my set-up. and i found issue with SecKeyRef. Let me explain the scenario
>
> I have performed following steps:
> • Got RSA public Key from server
> • Now strip RSA header from this public key
> • Add RSA key using SecItemAdd. <== It returns 0.
> • Now retrieve SecKeyRef using SecItemCopyMatching <== successfully returned SceKeyRef
> • Now using this reference , encrypt plain text with SecKeyEncrypt. <== successfully done
> • Now delete public key using SecItemDelete. <== returns 0
> The very first time, all calls are successful and encrypted data is decrypted successfully and of correct length, i.e., 32 bytes.
>
> The issue i am facing is, Second time onwards, on using the same calls, i found data decrypted on server is of some arbitrary length, sometimes 33/ 48/ 38 so on... but greater than 32 bytes
>
By second time on do you mean within the one execution context?
> On further debugging i found, every time while calling SecItemAdd, if i specify some random tag (which is not used till now) (tag is value corresponding to kSecAttrApplicationTag), then data encrypted with this key is successfully decrypted on server and of 32 bytes.
> But on using the same tag in SecItemAdd, data decrypted on server contains some random bytes after 32 bytes.
>
> Is there any issue with using kSecAttrApplicationTag or SecItemDelete function ?
>
> Can anybody please provide me some insight to it.
> Thanks
I encountered a similar issue on OS X when deleting and then recreating keychain items.
It might throw some light on the problem.
The docs for SecKeychainItemDelete state:
Do not delete a keychain item and recreate it in order to modify it; instead, use the SecKeychainItemModifyContent orSecKeychainItemModifyAttributesAndData function to modify an existing keychain item. When you delete a keychain item, you lose any access controls and trust settings added by the user or by other applications.
Something similar might be occurring here.
Rather than deleting the item you could try calling secItemUpdate.
Regards
Jonathan Mitchell
Developer
Mugginsoft LLP
http://www.mugginsoft.com_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden