Last active
October 14, 2020 00:00
-
-
Save dougvann/56d367ae1fa94b6bb6e9b60731fc2987 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function encryptData($data) { | |
$plainText = json_encode($data); | |
print '$Plaintext = json_encode($data)' . " \nVAL:$plainText \n \n"; | |
$encryptionKey = 'p@SSword'; | |
print "\$encryptionKey = 'p@SSword' \nVAL:$encryptionKey \n \n"; | |
$bytesToBeEncrypted = $plainText; | |
print "\$bytesToBeEncrypted = utf8_encode($plainText) \nVAL:$bytesToBeEncrypted \n \n"; | |
$passwordBytes = utf8_encode($encryptionKey); | |
print '$passwordBytes = utf8_encode($encryptionKey)'; | |
print "\nVAL:$passwordBytes \n \n"; | |
$saltBytes = array(1,2,3,4,5,6,7,8); | |
print '$saltBytes = array(1,2,3,4,5,6,7,8);' . "\n \n"; | |
$saltBytesstring = ""; | |
print "VAL:"; | |
print_r($saltBytes); | |
print '$saltBytesstring = "";' . "\n \n"; | |
for($i=0;$i<count($saltBytes);$i++){ | |
$saltBytesstring .= chr($saltBytes[$i]); | |
} | |
print 'for($i=0;$i<count($saltBytes);$i++){ echo $i; | |
$saltBytesstring .= chr($saltBytes[$i]); | |
}' . "\n \n"; | |
print "\$saltBytes = \nVAL: $saltBytesstring \n"; | |
print "note: the value of \$saltBytesstring is not a visible ascii value \n \n"; | |
$dev = hash_pbkdf2('sha256', $passwordBytes, $saltBytesstring, 10000, 48, true); | |
print '$dev = hash_pbkdf2(\'sha256\', $passwordBytes, $saltBytesstring, 10000, 48, true);'; | |
print "\n VAL:$dev \n \n"; | |
$key = substr($dev, 0, 32); //Keylength: 32 | |
print '$key = substr($dev, 0, 32); //Keylength: 32'; | |
print "\n VAL:$key \n \n"; | |
$iv = substr($dev, 32, 16); // IV-length: 16 | |
print '$iv = substr($dev, 32, 16); // IV-length: 16'; | |
print "\n VAL:$iv \n \n"; | |
$method = 'aes-256-cbc'; | |
print '$method = \'aes-256-cbc\';'; | |
print "\n VAL:$method \n \n"; | |
$encrypted = base64_encode(openssl_encrypt($bytesToBeEncrypted, $method, $key, OPENSSL_RAW_DATA, $iv)); | |
print '$encrypted = base64_encode(openssl_encrypt($bytesToBeEncrypted, $method, $key, OPENSSL_RAW_DATA, $iv));'; | |
print "\nVAL:$encrypted \n \n"; | |
$encrypted = UrlEncodeBase64($encrypted); | |
print '$encrypted = UrlEncodeBase64($encrypted);'; | |
return $encrypted; | |
} | |
function UrlEncodeBase64($str) { | |
// $str = str_replace('+', '.', $str); | |
// $str = str_replace('/', '_', $str); | |
// $str = str_replace('=', '-', $str); | |
$str = str_replace('+', '-', $str); | |
$str = str_replace('/', '_', $str); | |
$str = str_replace('=', '.', $str); | |
return $str; | |
} | |
$submission = array('Year' => 2020, 'PlanId' => 'P00000000001', 'Zipcode' => "06443", 'Expires' => '2020-10-13T23:59:59.303'); | |
print "\n \nVAL:\n" . encryptData($submission) . "\n \n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment