PHP License Key Generator

I am looking for a way to create license keys using a PHP script, and then transfer it to my application (Air, AS3) and read the data correctly in this application. For example, here is the code:

<?php error_reporting(E_ALL); function KeyGen(){ $key = md5(mktime()); $new_key = ''; for($i=1; $i <= 25; $i ++ ){ $new_key .= $key[$i]; if ( $i%5==0 && $i != 25) $new_key.='-'; } return strtoupper($new_key); } echo KeyGen(); ?> 

The key generates something like this: 1AS7-09BD-96A1-CC8D-F106. I want to add some information to a key email user, and then transfer it to the client (Air application), decrypt the data and go to the application.

Is it possible?

+4
source share
3 answers

Ok lets you break down what you ask:

Do you want to:

  • add information to the key Well, what information do you want to add? Do you want to make the key longer when you do this? Do you want this information to require a decryption key? In the roughest sense, this is entirely possible with PHP
  • email user
    PHP has a mail () function. It pretty much just works.
  • then pass it to the client (Air app)
    Does aerial application call this php script via an HTTP request? if so, set the content type and print the key on it.
  • decrypt data Let's go back to step 1, perhaps, but you need a key or not, and you don't care if the format changes. Also, don't you want to decrypt data in an AS3 application?
  • display in the application. If the AS3 application will display the key or decrypted data, then this is AS3, where you need to get it to display the data.
+3
source

If you just want to save some information, but โ€œencodeโ€ it using the character set you used above (0-9A-Z), you can use the algorithm below.

The code is an old Python program (3). This, of course, does not look like anything, and is not very verified, but I think it is better than nothing, since you do not have many answers yet. Simply transfer the code to PHP or AS. The reduce statements can be replaced, for example, by imperative style styles. Also note that // stands for integer division in Python.

It should also be fairly easy to apply some compression / encryption to it. Hope it looks like what you wanted. Here it goes.

 from functools import reduce class Coder: def __init__(self, alphabet=None, groups=4): if not alphabet: alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" self.alphabet = alphabet self.groups = groups def encode(self, txt): N = len(self.alphabet) num = reduce(lambda x,y: (x*256)+y, map(ord, txt)) # encode to alphabet a = [] while num > 0: i = num % N a.append(self.alphabet[i]) num -= i num = num//N c = "".join(a) if self.groups > 0: # right zero pad while len(c) % self.groups != 0: c = c + self.alphabet[0] # make groups return '-'.join([c[x*self.groups:(x+1)*self.groups] for x in range(len(c)//self.groups)]) return c def decode(self, txt, separator='-'): # remove padding zeros and separators x = txt.rstrip(self.alphabet[0]) if separator != None: x = x.replace(separator, '') N = len(self.alphabet) x = [self.alphabet.find(c) for c in x] x.reverse() num = reduce(lambda x,y: (x*N)+y, x) a = [] while num > 0: i = num % 256 a.append(i) num -= i num = num//256 a.reverse() return ''.join(map(chr, a)) if __name__ == "__main__": k = Coder() s = "Hello world!" e = k.encode(s) print("Encoded:", e) d = k.decode(e) print("Decoded:", d) 

Output Example:

 Encoded: D1RD-YU0C-5NVG-5XL8-7620 Decoded: Hello world! 
+1
source

with md5 you cannot do this because it is a one-way hash. You must use the decryption method to do this, since it uses a key for encoding and decoding. There are several php extensions that can do this, see the php manual. You can also use third-party software for this, for example. http://wwww.phplicengine.com

+1
source

All Articles