0

I'm working on an iOS app using Parse, and I need to simulate their encryption flow using Ruby for the website and browser extensions I'm building for it.

For generating the salt for AES, they have the following code in the iOS app:

NSString *str            =    user.email;
NSData *strData          =    [str dataUsingEncoding: NSUTF8StringEncoding];
NSData *encryptedData    =    [strData AESEncryptWithPassphrase:str]; // using the same key

What's puzzling me is dataUsingEncoding: NSUTF8StringEncoding -- it's obviously encoding the string in UTF-8, but when I see it in NSLog it seems quite different. So if str was "[email protected]", doing NSLog on strData outputs:

<72616e64 6f6d656d 61696c40 676d6169 6c2e636f 6d>

Now, how do I get that same output in Ruby? I can't get the right salt because of this ("[email protected]".encode("UTF-8") simply returns the email as expected). How can I simulate dataUsingEncoding in Ruby to get the same exact salt, is there something I'm missing?

Thanks

1 Answer 1

3

Try this:

"[email protected]".encode("UTF-8").bytes.to_a.map{ |x| x.to_s(16)}

and you will "see" what you want.

The hexadecimal representation of "[email protected]" with UTF-8 encoding is

<72616e64 6f6d656d 61696c40 676d6169 6c2e636f 6d>

But ruby shows you the string representation, which is "[email protected]". They are showing the same stuff in different ways.

Check here for more information.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.