Skip to content

Instantly share code, notes, and snippets.

@gboudreau
Last active June 27, 2020 17:27
Show Gist options
  • Save gboudreau/3cbaafc949eb326b7125 to your computer and use it in GitHub Desktop.
Save gboudreau/3cbaafc949eb326b7125 to your computer and use it in GitHub Desktop.
Nissan Connect API encryption using PHP
<?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