문제

I need to acces an API on https://btc-e.com/api/documentation. I've been googling and trying lots of stuff for 3 days right now and I completely lost any hope that I can access that API.

It needs POST request to be encrypted with SHA512 and signed with secret key.

So, I try to implement it in Objective C.

Function where I have issues

NSString *hmacForKeyAndData(NSString *key, NSString *data)
{
const char *cKey  = [key cStringUsingEncoding:NSASCIIStringEncoding];
const char *cData = [data cStringUsingEncoding:NSASCIIStringEncoding];
unsigned char cHMAC[CC_SHA512_DIGEST_LENGTH];
CCHmac(kCCHmacAlgSHA512, cKey, strlen(cKey), cData, strlen(cData), cHMAC);
NSData *enryptedData= [[NSData alloc] initWithBytes:cHMAC length:sizeof(cHMAC)];
// encryptedData seems to be in right form
// <ef56b041 12345678 12345678 12345678 a6128b61 12345678 f409507e 12345678 54a91f40 52f491e0 12345678 18942391 12345678 b2749b14 12345678 12345678>
NSString *result;

// HERE: I need to somehow convert NSData to NSString

return result;
}

I just cannot get how to encrypt this message right and how to convert it to string that I can then send as POST parameter :(

Can you please help me how to deal with SHA512 with key signature?

도움이 되었습니까?

해결책

The API failed to mention that they want the signature to be base64 encoded. This site gives a pretty good example of how to do so http://agerson.net/base64-encode-and-decode-nsstring-cocoa.

I think you are also confusing encryption with signatures. The API does not appear to ask you to encrypt you data. It asks you to sign your data. The enryptedData variable you have is the signature and does not need to be encrypted. Just do base64 encode on it and assign it to the Sign header.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top