Last active
June 27, 2020 17:27
-
-
Save gboudreau/3cbaafc949eb326b7125 to your computer and use it in GitHub Desktop.
Nissan Connect API encryption using PHP
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 encrypt($password, $key = 'uyI5Dj9g8VCOFDnBRUbr3g') { | |
$size = @call_user_func('mcrypt_get_block_size', MCRYPT_BLOWFISH); | |
if (empty($size)) { | |
$size = @call_user_func('mcrypt_get_block_size', MCRYPT_BLOWFISH, MCRYPT_MODE_ECB); | |
} | |
$password = pkcs5_pad($password, $size); | |
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB), MCRYPT_RAND); | |
$passcrypt = mcrypt_encrypt(MCRYPT_BLOWFISH, $key, $password, MCRYPT_MODE_ECB, $iv); | |
$encode = base64_encode($passcrypt); | |
return $encode; | |
} | |
function pkcs5_pad($text, $blocksize) { | |
$pad = $blocksize - (strlen($text) % $blocksize); | |
return $text . str_repeat(chr($pad), $pad); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment