Jakehh Posted April 16, 2010 Share Posted April 16, 2010 I am looking for a Similar type of encryption to what Windows uses for their license keys. and from what i've developed, it can be hacked pretty easily. <?PHP function randLetter() { $int = rand(0,26); $a_z = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $rand_letter = $a_z[$int]; return $rand_letter; } function license() { $license .= rand(0,9); $license .= randLetter(); $license .= rand(0,9); $license .= randLetter(); $license .= rand(0,9); $license .= "-"; $license .= randLetter(); $license .= randLetter(); $license .= rand(0,9); $license .= randLetter(); $license .= rand(0,9); $license .= "-"; $license .= rand(0,9); $license .= randLetter(); $license .= rand(10,99); $license .= randLetter(); $license .= "-"; $license .= randLetter(); $license .= randLetter(); $license .= rand(100,999); return $license; } license(); ?> Could anyone suggest a much easier and simple way compared to this? Link to comment Share on other sites More sharing options...
0 stereopixels Posted April 16, 2010 Share Posted April 16, 2010 What are you intending to do with the encryption? Link to comment Share on other sites More sharing options...
0 Hot Posted April 16, 2010 Share Posted April 16, 2010 Why not just use a one-way hash? $encrypted = sha1($unencrypted); Link to comment Share on other sites More sharing options...
0 Jakehh Posted April 16, 2010 Author Share Posted April 16, 2010 Its for a Licensing module. EG/ User signs up, it gives them the license key. And i don't want to use encryption because it won't contain any data. will only be useless random letters. Link to comment Share on other sites More sharing options...
0 Jakehh Posted April 16, 2010 Author Share Posted April 16, 2010 also, Sha1 is for losers. Lrn2Sha512 Link to comment Share on other sites More sharing options...
0 Hot Posted April 16, 2010 Share Posted April 16, 2010 also, Sha1 is for losers. Lrn2Sha512 To be perfectly frank, if you actually needed anything close to SHA-512 encryption, you would not be on a forum asking how to write a simple encryption algorithm. :sleep2: Bigger hashes are significantly slower to encode and take up more space to store. Your own license() function returns a value that is shorter than even an MD5 hash, let alone the current go-to standard of SHA-1. If you need to store some data with the key, simply give the hash a prefix or suffix with that data. Much like credit card companies give special significance to the first few digits of the numbers they issue. nvme 1 Share Link to comment Share on other sites More sharing options...
0 Jakehh Posted April 16, 2010 Author Share Posted April 16, 2010 Lol'd. Or you could simply just generate Random Keys :laugh: Link to comment Share on other sites More sharing options...
0 AnthonySterling Posted April 16, 2010 Share Posted April 16, 2010 function get_license($seed = null){ $hash = sha1( sprintf( '%s-%s', null === $seed ? str_shuffle(implode('', range('a', 'z'))) : $seed, microtime(false) ) ); return sprintf( '%s-%s-%s-%s-%s-%s', substr($hash, 0, 5), substr($hash, 5, 5), substr($hash, 10, 5), substr($hash, 15, 5), substr($hash, 20, 5), substr($hash, 25, 5) ); } Jakehh 1 Share Link to comment Share on other sites More sharing options...
0 boogerjones Posted April 16, 2010 Share Posted April 16, 2010 LOL, move this thread to the joke section. Windows uses a complex public-key encryption system for product keys. This guy wants something similar that can't be easily hacked? Link to comment Share on other sites More sharing options...
0 Argi Posted April 16, 2010 Share Posted April 16, 2010 It's not as simple as just generating random numbers. There's an algorithm used so that keys can be checked if they're in the valid format before they're sent to the server for activation. I'm actually kinda curious myself but I haven't bothered searching the net for anything. Link to comment Share on other sites More sharing options...
0 Jakehh Posted April 16, 2010 Author Share Posted April 16, 2010 LOL, move this thread to the joke section. Windows uses a complex public-key encryption system for product keys. This guy wants something similar that can't be easily hacked? I want it so i can hack it from the main server, so on demand i can find out if its a legit license or not. It's not as simple as just generating random numbers. There's an algorithm used so that keys can be checked if they're in the valid format before they're sent to the server for activation. I'm actually kinda curious myself but I haven't bothered searching the net for anything. Its stored in my site DB, and then again in the user's CMS download. So it would require to verify it. Link to comment Share on other sites More sharing options...
0 Stetson Posted April 16, 2010 Share Posted April 16, 2010 Just a quick way to make it more random would be to let each character be chosen from the full spectrum of 0-9 AND A-Z. Remember though that if you just use random keys without some sort of sequential method for generating them, you'll have to check for duplicates every time you generate a new one. Link to comment Share on other sites More sharing options...
0 Jakehh Posted April 16, 2010 Author Share Posted April 16, 2010 function get_license($seed = null){ $hash = sha1( sprintf( '%s-%s', null === $seed ? str_shuffle(implode('', range('a', 'z'))) : $seed, microtime(false) ) ); return sprintf( '%s-%s-%s-%s-%s-%s', substr($hash, 0, 5), substr($hash, 5, 5), substr($hash, 10, 5), substr($hash, 15, 5), substr($hash, 20, 5), substr($hash, 25, 5) ); } Thank you, worked greatly (Just applied variable to the sprintf then applied strtoupper() to it) Link to comment Share on other sites More sharing options...
Question
Jakehh
I am looking for a Similar type of encryption to what Windows uses for their license keys. and from what i've developed, it can be hacked pretty easily.
<?PHP function randLetter() { $int = rand(0,26); $a_z = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $rand_letter = $a_z[$int]; return $rand_letter; } function license() { $license .= rand(0,9); $license .= randLetter(); $license .= rand(0,9); $license .= randLetter(); $license .= rand(0,9); $license .= "-"; $license .= randLetter(); $license .= randLetter(); $license .= rand(0,9); $license .= randLetter(); $license .= rand(0,9); $license .= "-"; $license .= rand(0,9); $license .= randLetter(); $license .= rand(10,99); $license .= randLetter(); $license .= "-"; $license .= randLetter(); $license .= randLetter(); $license .= rand(100,999); return $license; } license(); ?>Could anyone suggest a much easier and simple way compared to this?
Link to comment
Share on other sites
12 answers to this question
Recommended Posts