From Anorexic Hog, 4 Years ago, written in PHP.
This paste is a reply to Untitled from Unique Hornbill
- view diff
Embed
  1. <?php
  2. function encrypt($plaintext, $password)
  3. {
  4.     $method     = "AES-256-CBC";
  5.     $key        = hash('sha256', $password, true);
  6.     $iv         = openssl_random_pseudo_bytes(16);
  7.     $ciphertext = openssl_encrypt($plaintext, $method, $key, OPENSSL_RAW_DATA, $iv);
  8.     $hash       = hash_hmac('sha256', $ciphertext, $key, true);
  9.     return $iv . $hash . $ciphertext;
  10. }
  11. function decrypt($ivHashCiphertext, $password)
  12. {
  13.     $method     = "AES-256-CBC";
  14.     $iv         = substr($ivHashCiphertext, 0, 16);
  15.     $hash       = substr($ivHashCiphertext, 16, 32);
  16.     $ciphertext = substr($ivHashCiphertext, 48);
  17.     $key        = hash('sha256', $password, true);
  18.     if (hash_hmac('sha256', $ciphertext, $key, true) !== $hash)
  19.         return null;
  20.     return openssl_decrypt($ciphertext, $method, $key, OPENSSL_RAW_DATA, $iv);
  21. }
  22.  
  23. function new_license(){
  24.  
  25. }
  26.  
  27. function validate_license($lic){
  28.         $license=explode("-", $lic);
  29.         ;
  30.         echo "\n".cntrl_summ($license['2'],0);
  31.          cntrl_summ($license['2'],0);
  32. }
  33.  
  34. function cntrl_summ ($num, $num_old, $last_num=false){
  35.          $x = (int)$num;
  36.          $s = 0;
  37.          while ($x <> 0) {
  38.                 $s = $s + $x % 10;
  39.                 $x = fmod($x ,10 );
  40.                 echo $x;
  41.          }
  42.          if ($x==0) {
  43.                 echo 0;
  44.         } else echo 1;
  45. }
  46.  
  47.  
  48. $k  = '. md5(rand());
  49. $sn = sha1('1314-6685-000-65908');
  50.  
  51. echo base64_encode(encrypt($k, $sn));
  52. validate_license('1314-6685-000-65908');