Last active
August 26, 2015 16:12
-
-
Save hachi-eiji/524f6f369f18438b955a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 -r "var_dump(openssl_encrypt('1.1.152d4544adcf10056c34559101f2c0af.0', 'aes-256-cbc', '0lwAogPqXGpkDMGj', 0, 'XWFYfWFOvZ7FGLyA'));" | |
string(64) "iyA6+tUYQYgjLQHTD1rTLg4VJXd3uPx9XJR3xPC439N936flzRuIWrHzGU1K2mA6" | |
*/ | |
var crypto = require('crypto'); | |
var _key = '0lwAogPqXGpkDMGj'; | |
var _iv = 'XWFYfWFOvZ7FGLyA'; | |
var _data = '1.1.152d4544adcf10056c34559101f2c0af.0'; | |
var key = crypto.createHash('sha256').update(_key).digest(); | |
var iv = _iv; | |
console.log('key:', key.toString(), 'iv:',iv.toString()); | |
var cipher = crypto.createCipheriv('aes-256-cbc', key, iv); | |
encrypted = cipher.update(_data, 'utf8', 'base64') + cipher.final('base64'); | |
var encoded = new Buffer(encrypted, 'binary').toString('base64'); | |
console.log(encoded); |
This file contains hidden or 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 sslPrm() | |
{ | |
return array("0lwAogPqXGpkDMGj","XWFYfWFOvZ7FGLyA","aes-256-cbc"); | |
} | |
function sslEnc($msg) | |
{ | |
list ($pass, $iv, $method)=sslPrm(); | |
if(function_exists('openssl_encrypt')) | |
return urlencode(openssl_encrypt(urlencode($msg), $method, $pass, false, $iv)); | |
else | |
return urlencode(exec("echo \"".urlencode($msg)."\" | openssl enc -".urlencode($method)." -base64 -nosalt -K ".bin2hex($pass)." -iv ".bin2hex($iv))); | |
} | |
function sslDec($msg) | |
{ | |
list ($pass, $iv, $method)=sslPrm(); | |
if(function_exists('openssl_decrypt')) | |
return trim(urldecode(openssl_decrypt(urldecode($msg), $method, $pass, false, $iv))); | |
else | |
return trim(urldecode(exec("echo \"".urldecode($msg)."\" | openssl enc -".$method." -d -base64 -nosalt -K ".bin2hex($pass)." -iv ".bin2hex($iv)))); | |
} | |
//example of usage: | |
$r= sslEnc("1.1.152d4544adcf10056c34559101f2c0af.0"); | |
$a = rawurlencode(openssl_encrypt("1.1.152d4544adcf10056c34559101f2c0af.0", "aes-256-cbc", "0lwAogPqXGpkDMGj", 0, "XWFYfWFOvZ7FGLyA")); | |
echo "result:".$a; | |
echo "\n"; | |
echo "result2:".$r; | |
echo "\n"; | |
echo bin2hex("0lwAogPqXGpkDMGj") ."<>". bin2hex("XWFYfWFOvZ7FGLyA") | |
?> |
This file contains hidden or 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
var _data = '1.1.152d4544adcf10056c34559101f2c0af.0'; | |
// passwordは | |
function encrypt(){ | |
var cipher = crypto.createCipher('aes-256-cbc', 'password'); | |
var encrypted = cipher.update(_data,'utf-8','hex')+ cipher.final('hex'); | |
console.log(new Buffer(encrypted, 'hex').toString('base64')); | |
} |
This file contains hidden or 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 sslPrm() | |
{ | |
$a = pack('H*',"5F4DCC3B5AA765D61D8327DEB882CF992B95990A9151374ABD8FF8C5A7A0FE08"); | |
$b = pack('H*',"B7B4372CDFBCB3D16A2631B59B509E94"); | |
return array($a, $b,"aes-256-cbc"); | |
//return array("0lwAogPqXGpkDMGj","XWFYfWFOvZ7FGLyA","aes-256-cbc"); | |
} | |
function sslEnc($msg) | |
{ | |
list ($pass, $iv, $method)=sslPrm(); | |
return urlencode(openssl_encrypt(urlencode($msg), $method, $pass, false, $iv)); | |
// if(function_exists('openssl_encrypt')) | |
// return urlencode(openssl_encrypt(urlencode($msg), $method, $pass, false, $iv)); | |
// else | |
// return urlencode(exec("echo \"".urlencode($msg)."\" | openssl enc -".urlencode($method)." -base64 -nosalt -K ".bin2hex($pass)." -iv ".bin2hex($iv))); | |
} | |
function sslDec($msg) | |
{ | |
list ($pass, $iv, $method)=sslPrm(); | |
return trim(urldecode(openssl_decrypt(urldecode($msg), $method, $pass, false, $iv))); | |
// if(function_exists('openssl_decrypt')) | |
// return trim(urldecode(openssl_decrypt(urldecode($msg), $method, $pass, false, $iv))); | |
// else | |
// return trim(urldecode(exec("echo \"".urldecode($msg)."\" | openssl enc -".$method." -d -base64 -nosalt -K ".bin2hex($pass)." -iv ".bin2hex($iv)))); | |
} | |
//example of usage: | |
$r= sslEnc("1.1.152d4544adcf10056c34559101f2c0af.0"); | |
//$a = rawurlencode(openssl_encrypt("1.1.152d4544adcf10056c34559101f2c0af.0", "aes-256-cbc", "0lwAogPqXGpkDMGj", 0, "XWFYfWFOvZ7FGLyA")); | |
echo "encode:".$r; | |
echo "\n"; | |
echo "decode:".sslDec($r); | |
echo "\n"; | |
?> |
This file contains hidden or 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
echo '1.1.152d4544adcf10056c34559101f2c0af.0' | openssl enc -aes-256-cbc -base64 -nosalt -K 306c77416f6750715847706b444d476a -iv 585746596657464f765a3746474c7941 | |
iyA6+tUYQYgjLQHTD1rTLg4VJXd3uPx9XJR3xPC439MZp4jLh9HNrHX7HEGcfRC6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment