Jump to content

random_bytes usage in email


Balderick

Recommended Posts

I would like to create a a random number with random_bytes(). Can I just store the random_bytes output in the database field?

Is that for instance more secure?

And, regarding to sending it by email, what is the advantage above sending a code like uniqid() or md5($_POST['var'] + microtime() ?

 

I see the screen output is a bit uncommon (with ? in a diamond ) does that have to do with the encryption? And is that the reason why reason bin2hex is used to decrypt?

 

this is the code I would like to use:

	<html>
	<center>
	<br><br><br>
	the output  of the function random_bytes is: 
	<br><br>
	<?php  

	$num = random_bytes(15);
	echo '<br><br>' . $num ;
	echo '<br><br> var dump of random_bytes with bin2hex: ' ;

	echo bin2hex($num);

	?>



	</center></html>
Link to comment
Share on other sites

Is that for instance more secure?

More secure than what?

 

And, regarding to sending it by email, what is the advantage above sending a code like uniqid() or md5($_POST['var'] + microtime() ?

What's the purpose? What are you using it for?

 

I see the screen output is a bit uncommon (with ? in a diamond ) does that have to do with the encryption?

Nothing is encrypted, you're just producing random bytes. Each byte can be one of 256 values. Not all of those bytes represent printable characters, so you're seeing what happens when you try to print a non-printable character. I don't know what your purpose is, but you can use base64_encode to change the encoding of the bytes to base64 which will contain only printable characters, and you can decode to get the original bytes back. But, like I said, I don't know what you're trying to do so I can't really suggest anything.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...