How to decrypt the text using Base64 encoding scheme algorithm - iphone

I have created code which takes a string from a text field and calls a encrypting method for doing encryption of that text using the base64 encoding scheme. But I don't have any idea how to create the decryption method for decrypting whatever value I am getting from the method.

Save yourself some trouble and download the NSData Base64 category.
Then you can encode or decode using a single line.

Related

Why do you use base64 URL encoding with JSON web tokens?

The Scenario:
I'm reading about JSON web tokens at this link (https://medium.com/vandium-software/5-easy-steps-to-understanding-json-web-tokens-jwt-1164c0adfcec). It outline how to create a JSON web token, you create a header and a payload, and then create a signature using the following pseudocode:
data = base64urlEncode( header ) + “.” + base64urlEncode( payload )
hashedData = hash( data, secret )
signature = base64urlEncode( hashedData )
My Question:
Why does the pseudocode use base64urlEncode when creating data and signature?
Scope Of What I Understand So Far:
Base64 allows you to express binary data using text characters from the Base64 set of 64 text characters. This is usually used when you have a set of data that you want to pass through some channel that might misinterpret some of the characters, but would not misinterpret Base64 characters, so you encode it using Base64 so that the data won't get misinterpreted. Base64 URL encoding, on the other hand, is analogous to Base64 encoding except that you use only a subset of the Base64 character set that does not include characters that have special meaning in URLs, so that if you use the Base64 URL encoded string in a URL, its meaning won't get misinterpreted.
Assuming my understanding there is correct, I'm trying to understand why base64urlEncode() is used in computing data and signature in the pseudocode above. Is the signature of a JSON web token going to be used somewhere in a URL? If so, why is data base64urlEncoded as well before hashing. Why not just encode the signature? Is there something about the hash function that would require its data parameter to be Base64 URL encoded?
When using the OAuth Implicit Grant, JWTs may be transferred as part of URL fragments.
That is just an example, but I guess in general it was presumed that JWTs might be passed through URLs, so base64urlEncodeing them makes sense.
The first line of the IETF JWT standard abstract even says:
JSON Web Token (JWT) is a compact, URL-safe means of representing claims to be transferred between two parties.
(Note that the OAuth Implicit Grant is no longer recommended to be used.)

How can I reverse engineer the encode method used here?

I have a string:
RP581147238IN which gets encoded as A3294Fc0Mb0V1Tb4aBK8rw==
and another string:
RP581147239IN which gets encoded as A3294Fc0Mb1BPqxRDrRXjQ==
But after spending a day, I still cannot figure out what is the encoding process.
The encoded string looks like its base64 encoded.
But when I decode it, it looks like:
base64.decodestring("A3294Fc0Mb0V1Tb4aBK8rw==")
\x03}\xbd\xe0W41\xbdA>\xacQ\x0e\xb4W\x8d
The base 64 decoded string now is looking like a zlib compressed string
I've tried to further use zlib decompression methods but none of them worked.
import zlib, base64
rt = 'A3294Fc0Mb1BPqxRDrRXjQ=='
for i in range(-50, 50):
try:
print(zlib.decompress(base64.decodestring(rt), i));
print("{} worked".format(i))
break
except:
pass
But that did not produce any results either.
Can anybody figure out what is the encoding process used here. #Nirlzr, I am looking at you for the heroic answer you provided in Reverse Engineer HTTP request.
The strings seem to be Base64 encoded and the underlying decoded data seems to be encrypted. Encrypted data can not be directly represented as a string and it is common the Base64 encode encrypted data when a string is required.
If this is the case you need to decrypt the decoded data and ignorer to accomplish that you would need the encryption key.
Note: In general it is not productive to compress such short items.
If you put your data strings side by side:
RP581147238IN A3294Fc0Mb0V1Tb4aBK8rw==
RP581147239IN A3294Fc0Mb1BPqxRDrRXjQ==
You can see that source strings have only character difference, but encoded version contains 12 different characters:
----------8-- ----------0V1Tb4aBK8rw--
----------9-- ----------1BPqxRDrRXjQ--
Encoded data has similar paddings at the end as base64, but definitely it is not base64. Probably crypted with some SHA-like algorithm. With the data you provided, I would say that it is not possible to reverse-engineer the encoding process. Probably more data would not help much either.

How to post uiimage to soap Srevice in binary formate

I want to post uiimage into soap service and input image is into binary formate
"<ExpenseDetailReceipt>%#</ExpenseDetailReceipt>"
and send this appdelegate.imgBMeal data
appdelegate.imgBMeal=UIImagePNGRepresentation(appdelegate.imgMeal);
as image but there is some problem and I get please send data in correct formate
please help me how to do this
Soap is basically an xml which is a string. Hence, your UIImagePNGRepresentation(appdelegate.imgMeal) method which does not return a string fails. The output of the UIIagePNGRepresentation() is an NSData object which you can covert to a string by using Base64 encoding. (You may use any other encoding of your choice). For more about coverting NSData to NSString using Base64 encoding, there is an SO link with many answers.. here. You may also need to check with your service provider about the encoding decoding parts.

AES256 Decryption Problem

I have been using the encryption/decryption as detailed here. Following is the scenario :
Retrieved the encrypted data from the server, with utf-8 encoded, xml content.
I am able to decrypt the data to NSData format using the decryption method(AES256 Decryption). But unable to convert the NSData hence obtained to NSString , by using NSUTF8/NSASCII encodings.
the string to decrypt ,key are as follows:
the encryted string:
*Ti6IFA8agg8XdfYQ/bzpW9OkGM3q3bZMsHrT9lRsg27e8la+GqgE
ZiBpVbpFDJ3f1qgaH+vpI0YjsJtvU6rL2YkUHD6rgg3IjyVMmdPtz5U9baPWHFG+/jlWpVULRTP4
PHckEQaQekYo9yjaGWKfWNADzpFUlS99TnWc/Xr/2loWUoatV6mmZDKkIg6sm5BRHaR3MEDoH8bn
quA/RVWc4hc0H4XhMA0f8RsE+i9OhqbqHfkqLss114m9IUICeqBM16mH93VO7jmTTSfSm1YQFSHo
31Lqchmh/baMhaBfd+U1HEkv+Wfop/aaAlKK8Mc7kw+gZMzG+YKGMk7tkAIjepxNK0MD6jxFEtaj
bxPUBSl0ewYXAIFRsS1up44w39MH9L2QrKM7RF1s2SZOvNOD4O1cFr22gGy3GQz+syEV/nn4hest
8koob8RKmUZTNrwkfa4xe8G7FMRYfM8fEpm6gy/hWEvwmNo/X2r3SNo7h5q1x19pBKtO1dBUW8Nf
kV5G5EyBg6HQv9NBcROYKgjLhJ/VNn1SiH+wh2AcsxwG/dELqHfSBWF7c2jDM3ggBCJWf2P/BwKO
eY+g+rHSzAtwtR2tZFZUDHpO/P6GvMw/D7OA7OvqmDWh2jOF4MlzFBCaG7FJAm8BJ2GTCK/V4VQh
nloG2Wgtr4PLCRh8GXZnMCzrvxcR7l47/8Um7u9HcYVg7dUnfuil3r85niUAobN2fdDNrLcjJ8Eg
tanDfPQhz+FBPzt1ygVaYo6Ko3Lq0juHL42vBr4GS2I2UO/wDd+PE6FUL5rXrCHUgL922tnebQuJ
DNIaymNxZ9JLMb2SSSUu*
Key:1ml4nyKW/DggMNhU2qJrvCp80ycHsy32fbSgtdvODGM=
Note:Iam using ECB mode in the ccdecrypt for decryption.As this mode is used at the server side while encrypting data.
Have you see this - Convert UTF-8 encoded NSData to NSString

XML data text + binary

I built an iPhone app that is getting information from a server (this is also a server that I built).
The data from the server is XML and I use the XML parser to parse the message.
What I want is to add an image to be sent from the server, and I am asking if I can add binary data of such an image to the XML message. For example 10 tags will be text and 1 tag will be binary (the image). So when the XML parser gets to the binary tag, it inserts the data to NSDATA object and the rest of the tags will be inserted to NSString.
Does the XML parser of Cocoa can handle this situation?
If not, what do you think will be the easiest way to do this with one connection to the server so that the data from the server is sent once.
To transfer binary data wrapped in XML, encode it using e.g. Base64, which turns your binary data into characters that won't mess up your XML.
You can transfer the image data, encoded using Base64. There is this NSData category by Matt Gallagher that adds Base64 decoding support to NSData (dateFromBase64String). You can find it on his Cocoa with love website.
Mind you that encoding images in Base64 adds about 33% in file size.