I want to Implement random_bytes(16) in Objective C, In PHP output string is something like this:
d�g���&���$�
I tried this code for Objective C:
uint8_t randomBytes[16];
int result = SecRandomCopyBytes(kSecRandomDefault, 16, randomBytes);
NSString *iv = [NSString stringWithFormat:@"%s",randomBytes];
But this is not like PHP output.
Please help me.
In the PHP output, the � character is used to replace an unknown or unrepresented character. In order to print the output of raw bytes you will need to convert them to a readable format such as HEX or Base64, for example. If you just print the raw bytes directly, the output may differ depending on the environment. So the best way to compare between different environments is to convert them first and then do the comparison. So for HEX, in PHP, this can be done fairly easily using bin2hex
In your iOS environment you already have from your code above:
To convert that array of bytes into a string showing the hex representation: