0

I'm trying to convert a hex string into base64 on iPhone. The hex is:

5289be07c5c7edcc18f3a02c7b81c110b8637f8b2ddbc29cdabcbd7e394c1695

But I cant's seem to get the base64 version of this, which is:

Uom+B8XH7cwY86Ase4HBELhjf4st28Kc2ry9fjlMFpU=

How would I get this base64 string?

cannyboy
  • 24,180
  • 40
  • 146
  • 252

1 Answers1

1

Since you are using SHA256 (I also use it), I assume you get an NSData output before you convert it to a hex string. Take that data, and use the category method shown in this question (the one with the most upvotes, that actually has the code inlined)

Community
  • 1
  • 1
borrrden
  • 33,256
  • 8
  • 74
  • 109
  • I've added the method which handles the SHA256. I can't see a way that it uses NSData..? – cannyboy Apr 16 '12 at 13:31
  • What do you mean? You are getting the NSData from the CommonCrypto library right? Well...you get the raw bytes back and you can turn them into NSData using NSData dataWithBytes. Then, you can pass that as a parameter to the function shown in the answer above. – borrrden Apr 16 '12 at 13:45
  • 1
    Oh, I see you edited your question...You can convert cHMAC to NSData after you've sent it to the CC function (using dataWithBytes). – borrrden Apr 16 '12 at 13:47