Skip to content

Instantly share code, notes, and snippets.

@creativefull
Created January 19, 2018 16:50
Show Gist options
  • Save creativefull/b613ce3f6f94c009e3ae7155e54e21bf to your computer and use it in GitHub Desktop.
Save creativefull/b613ce3f6f94c009e3ae7155e54e21bf to your computer and use it in GitHub Desktop.
function hex(buffer) {
var hexCodes = [];
var view = new DataView(buffer);
for (var i = 0; i < view.byteLength; i += 4) {
// Using getUint32 reduces the number of iterations needed (we process 4 bytes each time)
var value = view.getUint32(i)
// toString(16) will give the hex representation of the number without padding
var stringValue = value.toString(16)
// We use concatenation and slice for padding
var padding = '00000000'
var paddedValue = (padding + stringValue).slice(-padding.length)
hexCodes.push(paddedValue);
}
// Join all the hex strings into one
return hexCodes.join("");
}
function sha256(str) {
// We transform the string into an arraybuffer.
var buffer = new TextEncoder("utf-8").encode(str);
return crypto.subtle.digest("SHA-256", buffer).then(function (hash) {
return hex(hash);
});
}
function submitData() {
$.ajax({
url : url,
method : 'POST',
data : data,
success : function(msg) {
console.log(msg)
}
})
}
function x() {
sha256(Math.random()).then(function(digest) {
data.username = digest
data.name = digest
data.email = digest + '@gmail.com'
data.emailconfirm = digest + '@gmail.com'
console.log(data)
submitData()
});
}
var data = {
name:'Hello world',
email:'[email protected]',
subject:'Hello bug',
message:'hello saya dimana ?',
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment