Author

Topic: PHP Secret Key Generating Script (Read 999 times)

hero member
Activity: 588
Merit: 500
Get ready for PrimeDice Sig Campaign!
September 28, 2014, 02:37:22 PM
#5
You could use a GUID but it doesn't really matter, as long as it is long enough (not brute forceable) its fine.
newbie
Activity: 24
Merit: 0
September 28, 2014, 02:28:42 PM
#4
why not just use GUID almost all enterprise platforms use it. It is simple to use and generates completely random strings ex(c184964b-2263-40a0-8f4d-33d0696e452b)

http://php.net/manual/en/function.com-create-guid.php
hero member
Activity: 588
Merit: 500
Get ready for PrimeDice Sig Campaign!
September 28, 2014, 11:32:32 AM
#3
Are you sure this is strong randomness?
Yes, I don't see why it isnt. Its just making random characters so we don't need that to be random.
TCM
sr. member
Activity: 251
Merit: 250
September 28, 2014, 05:07:08 AM
#2
Are you sure this is strong randomness?
hero member
Activity: 588
Merit: 500
Get ready for PrimeDice Sig Campaign!
September 28, 2014, 02:38:25 AM
#1
I have made a very short secret generating script for if you need to make secret keys for casinos. This makes 3650 days worth of keys (you can easily make more, just change one number) to last 10 years. It generates and inserts the original secret (the thing you use and reveal 24 hours later), and the encrypted version which you release instantly, and it there at any time. It also associates a day per each pair. It inserts it all into a mysql database, but you can obviously change this, maybe insert into a csv file or something else. It is written in php.
This assumes you have a table with 3 columns, date, hash, and secret. You can change the table name if you want, and the hash algorithm. Its up to you what you do with it.
Source code:

Code:
require('conn.php');
// ^ connect to the database on this line. The mysql connection is on the object $db
$e=1;
$start_date date('n/j/Y');
for (
$i 1$i <= 3650$i++) {
$next_date strtotime($e++." day"strtotime($start_date));
$date date('n/j/Y',$next_date);
    
$key substr(str_shuffle(abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ),01) . substr(str_shuffle(aBcEeFgHiJkLmNoPqRstUvWxYz0123456789),031);
    
$hashkey hash('sha256'$key);
    
$stmt $db->prepare('INSERT INTO crypti_secrets (date, hash, secret) VALUES (:date, :hash, :secret)');
$result $stmt->execute(array(
'date' => $date,
'hash' => $hashkey,
'secret' => $key,
));
}
?>
Please donate if you found this helpful: 16MtvTUvqwwKwV87nayxPLHTJJZNGPa9qw
Jump to: