Reputation: 11000
I have a server that is not using SSL, so I'm trying to find a way to secure the data being passed to the server. My first thought was jCryption, but it is not exactly what I need. So what I decided is that I could just pre-hash the password and send it to the server for comparison. So my question is, is there a sha1 utility that can be used for password verification purposes with PHP?
Upvotes: 5
Views: 17391
Reputation: 17691
There it is
async function sha256(message) {
// encode as UTF-8
const msgBuffer = new TextEncoder().encode(message);
// hash the message
const hashBuffer = await crypto.subtle.digest('SHA-1', msgBuffer);
// convert ArrayBuffer to Array
const hashArray = Array.from(new Uint8Array(hashBuffer));
// convert bytes to hex string
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
return hashHex;
}
Upvotes: 0
Reputation: 3257
Try the Stanford Crypto library. It's pretty comprehensive but if you just need a single hashing function you can extract it from the core (it has sha1 and 256).
Upvotes: 7
Reputation: 26189
I think that's what you're looking for: http://phpjs.org/functions/sha1:512
Upvotes: 2
Reputation: 13097
You shouldn't be using SHA1 to do your hashing anymore, since it's been broken for a while. Try SHA256.
Upvotes: 4