0

I have the following code that creates an encryption in PHP:

$password = "helloworld";
$passwordupper = strtoupper($password);
$passwordencode = mb_convert_encoding($passwordupper, 'UTF-16LE');
$passwordsha1 = hash("SHA1", $passwordencode);
$passwordbase64 = base64_encode($passwordsha1);

The instructions I have from the system I'm trying to connect to states:

The encoding process for passwords is: first convert to uppercase, then Unicode it in little-endian UTF 16, then SHA1 it then base64 encode it.

I think I'm doing something wrong in my code. Any ideas?

Cᴏʀʏ
108k20 gold badges169 silver badges201 bronze badges
asked Jun 5, 2014 at 15:21
3
  • 2
    sha1 hash can either be raw binary, or a base64-encoded string to begin with. e.g. $raw = sha1($string, true) v.s. $encoded = sha1($string). you'd better try both variants, because you may be double-base64-encoding. Commented Jun 5, 2014 at 15:24
  • Perfect Marc B, that did the trick! Commented Jun 5, 2014 at 15:25
  • 1
    I strongly recommend using built-in password_hash() method (PHP >= 5.5) instead of hash() us.php.net/manual/en/function.password-hash.php Commented Jun 5, 2014 at 15:30

1 Answer 1

1

Answer solved by Marc B above in comments:

sha1 hash can either be raw binary, or a base64-encoded string to begin with. e.g. $raw = sha1($string, true) v.s. $encoded = sha1($string). you'd better try both variants, because you may be double-base64-encoding.

answered Jun 5, 2014 at 15:32
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.