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
Related
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.
I'm in quite a pickle, I'm acquiring user input in Arabic which is stored in a NSString.
The string is displayed properly both in the app and the debug window.
Here's my problem: the string is added to a NSMutableDictionary then serialized to JSON
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictionary
options:NSJSONWritingPrettyPrinted
error:&error];
The data is then POSTed to the server, but the once Arabic content is represented as ????
This is obviously an encoding issue. I can't find the proper method to encode my NSString with UTF-8 and still add it to the Dictionary.
AddingPercentEncoding will encode it as URL UTF-8 encoding which is not what I'm after.
The only reasonable encoding I find is [NSString UTF8String] which turns the string to const char * that is not an NSObject.
What I'm really after is: مرحبا UTF-8 ---> ÙرØبا
The decoding works perfectly, if the iOS app receives JSON with such representation, the resulting NSDictionary will hold a key that returns the proper value in Arabic.
Thank you for your help! :D
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.
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.
I am new to Encryption/ Decryption. I want to encrypt a NSString variable value using key. Also I want to decrypt the encrypted data . I want to apply AES -128 Algorithm.
Please suggest sample code or useful link.
I found this through a Google search on the terms aes nsstring site:stackoverflow.com:
AES Encryption for an NSString on the iPhone