Privacy/Features/DOMCryptAPI/UseCases: Difference between revisions

Jump to navigation Jump to search
Line 40: Line 40:
SHA 256 hashes are handy for storing passwords and generating checksums (among other uses)
SHA 256 hashes are handy for storing passwords and generating checksums (among other uses)


Example code uses the hashing API: '''window.cipher.hash.*'''
Example code uses the hashing API: '''window.crypto.hash.*'''
 
[Constructor(in DOMString algorithm)]
08.interface CryptoHash {
09.void append(in ArrayBuffer data);
10.ArrayBuffer finish();
11.};


<pre class="brush:js;toolbar:false;">
<pre class="brush:js;toolbar:false;">
var myPassword = "5ekr3tPa55w0rd";


window.cipher.hash.SHA256(myPassword, function callback(aHash) {
var hasher = new window.crypto.hash("RS256");
   myApp.doSomethingWithAHash(aHash);
var myData = "1234567890abcdefghijklmnopqrstuwxyz";
});
var arrBufferView = new Int8Array(myData.length);
 
for (var i = 0; i < myData.length; i++) {
   arrBufferView[i] = myData.charCodeAt(i);
}
 
hasher.append(arrBufferView);
 
var hashed = hasher.finish();


// Another idea: generating a file checksum in conjunction with the FileAPI
// Another idea: generating a file checksum in conjunction with the FileAPI
564

edits

Navigation menu