how to get the UTF8 binary value of a NSString - iphone

So I am wanting to send a request to a server I am working with, it requieres the binary value of a (utf-8 formatted nsstring) if there is such a thing, I have read that NSStrings are unicode formatted...
basically the idea is to send the value of the nsstring to the server without the added 3 byte header that UTF8 applies to the front of a string. This is because the server knows I will be sending it UTF8 formatted string in binary format so to save unnessacery formatting values that could bloat my requests I would like to try and do it this way.
dose any one have any ideas on how I might achieve this? I'm currently reading up about NSStrings on the apple docs, but there is so much to read and process I'm hoping someone can provide me some insight.
I don't have any code to show for this atm because I'm only in the planning and understanding phase of this, and to move forward I need to understand how this might be done so I can start coding it :)
any help would be greatly appreciated :)

NSString has a UTF8String method. It returns chars and chars are bytes. Does that work?
-(const char *)UTF8String
Return Value:
A null-terminated UTF8 representation of the receiver.
more info on it here.
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html

Related

User-Token which decode/decryption algorithm is that?

I have a string, but what I want to know is how this is generated?
3C+msMRwFDOcepm960C2kUfeFdBe2WoWLFATI+u7EKiFt9nqdPuI6nXIByUhBeNoCqaivEHp/dHimnfAeT0n7ZsZU6AmJkONCulPOLd8q09i+EzfWhW0GJmnvSIC3YEh5kuZOF62E63f12gjESKwyYVq4Y/iWcAu2TdyueX977U5O4BdLIEbDsmjSUhKLfiH8RvaGZrj4OpggOvpytsqcQ==
I did some research over the last days, and it seems its an base64 encoding but here we have also special characters in the string like "/+=". The plain text should be b33912c6-b805-412b-9660-b80186fc3b9f, but no encoding/encryption method I found online could get the same string.
Which encryption or encoding algorithm is used here?

I need help decoding (what I believe) is a base64 encoded message

I was given a encoded message as a challenge, and I am completely lost. Sorry if the answer to this is extremely obvious, but I cannot figure out what this code is supposed to represent. The code is:
JVCEK6CNIRCXOTKEIFTU2RCFPBGVIQLYJVCECZ2NIRCXQTKUIF4E2RCBM5GUIRLYJVKEC52NIRAWOTKEIV4E2VCBO5GVIRLHJVCEC6CNKRCXOTKUIFTU2RCBPBGUIRLYJVKEKZ2NIRAXQTKEIV4E2VCFM5GUIRLYJVKEC6CNKRCWOTKEIV4E2VCBPBGVIRLHJVCEK6CNKRAXQTKUIVTU2RCBPBGUIRLYJVKECZ2NIRCXQTKUIV3U2RCFM5GUIRLYJVCEK6CNKRCWOTKEIV4E2VCBPBGUIRLHJVCEK6CNKRAXQTKEIFTU2RCFPBGVIQLYJVCEKZ2NIRCXQTKEIF3U2VCBM5GUIRLYJVCEC6CNIRCWOTKEIF4E2RCFPBGVIQLHJVCEK6CNIRAXOTKUIVTU2RCFPBGUIRLYJVKEKZ2NIRCXQTKEIV4E2RCFM5GUIQLYJVCEK6CNKRCWOTKEIV4E2VCBPBGVIRLHJVCEK6CNIRAXOTKEIVTU2RCFPBGVIQLYJVCECZ2NIRCXQTKEIF3U2VCFM5GUIRLYJVCEK52NIRAWOTKEIF4E2VCFPBGVIRLHJVCEK6CNKRAXQTKUIFTU2RCBPBGVIRLYJVCEKZ2NIRCXQTKEIV4E2VCFM5GUIRLXJVCEK52NIRAWOTKEIV4E2RCBPBGVIRLHJVCEC6CNKRAXQTKEIVTU2RCFO5GVIQLXJVKEKZ2NIRCXOTKEIV3U2VCBM5GUIRLXJVKEK52NIRCWOTKEIV3U2VCBO5GVIQLHJVCEK52NIRCXOTKEIFTU2RCFO5GUIQLXJVCEKZ2NIRAXQTKUIF3U2RCBHU======
I believe it is base64 because of the = trailing at the end, but when converting it to ASCII, I get a bunch of nothing (making me think it is something else). I am not really asking for a direct answer to what the string is, but rather where I can go from here. I have already tried converting the binary value to jpg, but to no avail. Any help is greatly appreciated! (I also noticed it repeated JV*E a lot, I do not know whether that is significant or not.)
It's more likely base32 than base64, since there are no lower case letters, 1s, 8s, 9s, +s, or /s. Decoding it as base32 produces:
MDExMDEwMDAgMDExMTAxMDAgMDExMTAxMDAgMDExMTAwMDAgMDExMTAwMTEgMDAxMTEwMTAgMDAxMDExMTEgMDAxMDExMTEgMDExMTAxMTEgMDExMTAxMTEgMDExMTAxMTEgMDAxMDExMTAgMDExMTEwMDEgMDExMDExMTEgMDExMTAxMDEgMDExMTAxMDAgMDExMTAxMDEgMDExMDAwMTAgMDExMDAxMDEgMDAxMDExMTAgMDExMDAwMTEgMDExMDExMTEgMDExMDExMDEgMDAxMDExMTEgMDExMTAxMTEgMDExMDAwMDEgMDExMTAxMDAgMDExMDAwMTEgMDExMDEwMDAgMDAxMTExMTEgMDExMTAxMTAgMDAxMTExMDEgMDExMDExMTEgMDEwMDEwMDAgMDExMDAxMTEgMDAxMTAxMDEgMDEwMTAwMTEgMDEwMDEwMTAgMDEwMTEwMDEgMDEwMTAwMTAgMDEwMDEwMDAgMDEwMDAwMDEgMDAxMTAwMDA=
Hopefully, that helps.

Base58 Encoder function in PostgreSQL for TEXT

Can anyone help me to implement Base58 encoding stored procedure in PostgreSQL.
I've found answer for numbers but I'm looking for similar stored procedure that can accept TEXT or VARCHAR value.
On this very rare occasion I'm going to suggest you don't do this. It will be computationally possible but highly inadvisable.
https://en.wikipedia.org/wiki/Base58
In contrast to Base64, the digits of the encoding don't line up well
with byte boundaries of the original data. For this reason, the method
is well-suited to encode large integers, but not designed to encode
longer portions of binary data.
To put this another way, Base58 is not designed to encode strings / text. Your main alternatives are:
Base64 which if copied manually by a human, the human may make mistakes. Otherwise Base64 is safe to copy / paste
Hexadecimal which is easily copied by humans but significantly longer than Base64
If you feel you really need Base58 and not Base64 then it may be worth editing your requirements into your question. This may help someone give an answer more specific to your requiremnts:
What are these strings you need to convert (examples are preferable)?
Why do they need to be Base58 and not Base64 (what other system are you passing these to)?

How to auto detect a String encoding?

I have a String which contains some encoded values in some way like Base64.
The problem is that I really don't know if it's actually Base64 (there are A-Z, a-z. 0-9, +, /) so it can be some any other code that i'm not familiar with.
Is there a way or any other online site to send him an encoded input and it can tell me in which code is it?
NOTE:
I'm not asking how to know if my String is UTF-8 or iso-8859-1 or something like that.
What I need is to know in which is my code is encoded.
EDIT:
To be more clear,
I need something to get an input like: 23Nzi4lUE4qlc+Pmc3blWMS1Irmgo3i8UTQHhoL7VyzqpEV/i9bDhoiteZ0a7/TqcVSkrXR89V2Yj7tEFDGJx4gvWEBs= this is the encoded String that I have.
The output should be the type of the encoded String and it's decoding like:
Base64 -> "Big yellow fish is swimming in the tube."
Maybe there is some program which get's an input and tries to decode it with a list of coding types (Base64 and etc.). The output doesn't really matter because it's the users decision if it's good or not.
This site handles base64 de/encoding.
Since Base64 is just one instance of a class of encoding schemes ( specifically, encoding a bit stream as base_<n> number ), you probably will never fare better than testing for just a couple of standard encoding schemes.
You either check the well-formedness of the encoding scheme or try to decode without getting an error thrown using a web service or your own code.
In (possibly pathological) cases there will be more than one encoding scheme for which a given octet stream will successfully decode.
Best practice would be to take the effort invested into setting up the verification to committing the data provider to one (or 'a few') encoding(s) first (won't always be possible, of course).

Stig JSON library parse error: How do you accommodate new lines in JSON?

I have some xml that is coming back from a web service. I in turn use xslt to turn that xml into json (I am turning someone else's xml service into a json-based service). My service, which is now outputting JSON, is consumed by my iphone app using the de facto iphone json framework, SBJSON.
The problem is, using the [string JSONValue] method chokes, and I can see that it's due to line breaks. Lo and behold, even the FAQ tells me the problem but I don't know how to fix it.
The parser fails to parse string X
Are you sure it's legal JSON? This framework is really strict, so won't accept stuff that (apparently) several validators accepts. In particular, literal TAB, NEWLINE or CARRIAGE RETURN (and all other control characters) characters in string tokens are disallowed, but can be very difficult to spot. (These characters are allowed between tokens, of course.)
If you get something like the below (the number may vary) then one of your strings has disallowed Unicode control characters in it.
NSLocalizedDescription = "Unescaped control character '0x9'";
I have tried using a line such as: NSString *myString = [myString stringByReplacingOccurrencesOfString:#"\n" withString:#"\\n"];
But that doesn't work. My xml service is not coming back as CDATA. The xml does have a line break in it as far as I can tell (how would I confirm this). I just want to faithfully transmit the line break into JSON.
I have actually spent an entire day on this, so it's time to ask. I have no pride anymore.
Thanks alot
Escaping a new line character should work. So following line should ideally work. Just check if your input also contains '\r' character.
NSString *myString = [myString stringByReplacingOccurrencesOfString:#"\n" withString:#"\\n"];
You can check which control character is present in the string using any editor which supports displaying all characters (non-displayable characters as well). e.g. using Notepad++ you can view all characters contained in a string.
It sounds like your XSLT is not working, in that it is not producing legal JSON. This is unsurprising, as producing correctly formatted JSON strings is not entirely trivial. I'm wondering if it would be simpler to just use the standard XML library to parse the XML into data structures that your app can consume.
I don't have a solution for you, but I usually use CJSONSerializer and CJSONDeserializer from the TouchJSON project and it is pretty reliable, I have never had a problem with line breaks before. Just a thought.
http://code.google.com/p/touchcode/source/browse/TouchJSON/Source/JSON/CJSONDeserializer.m?r=6294fcb084a8f174e243a68ccfb7e2c519def219
http://code.google.com/p/touchcode/source/browse/TouchJSON/Source/JSON/CJSONSerializer.m?r=3f52118ae2ff60cc34e31dd36d92610c9dd6c306