Last active
July 25, 2021 14:13
-
-
Save makotokato/f70b4b6a7ea2c7fa2482 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?DOCTYPE html> | |
<html> | |
<head> | |
<script> | |
var crypto = window.crypto; | |
var data = convertStringToArrayBufferView('ABCDEFGHIJKLMNOP'); | |
var vector = crypto.getRandomValues(new Uint8Array(16)); | |
function convertStringToArrayBufferView(str) | |
{ | |
var bytes = new Uint8Array(str.length); | |
for (var iii = 0; iii < str.length; iii++) | |
{ | |
bytes[iii] = str.charCodeAt(iii); | |
} | |
return bytes; | |
} | |
function doBench() | |
{ | |
document.getElementById('status').innerHTML = "starting"; | |
crypto.subtle.generateKey( | |
{ | |
name:'AES-CBC', | |
length: 128 | |
}, true, ['encrypt', 'decrypt']).then(function(result) { | |
var startTime = new Date(); | |
var finished = 0; | |
for (var i = 0; i < 10000; i++) { | |
crypto.subtle.encrypt( | |
{ | |
name: 'AES-CBC', | |
iv: vector | |
}, result, data).then(function(result) { | |
finished++; | |
if (finished == 10000) { | |
document.getElementById('result').innerHTML = new Date() - startTime + "ms"; | |
} | |
}).catch(function(e) { | |
document.getElementById('status').innerHTML = e.message; | |
}); | |
} | |
}).catch(function(e) { | |
document.getElementById('status').innerHTML = e.message; | |
}); | |
} | |
</script> | |
</head> | |
<body> | |
<div id="result"></div> | |
<div id="status"></div> | |
<input type="button" value="doBench" onclick="doBench()"></input> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment