Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Crypto perf test</title>
    <script src="https://cdn.rawgit.com/vibornoff/asmcrypto.js/release/asmcrypto.js"></script>
</head>
<body>
    <!--button onclick="asmcr()">asmCrypto</button-->
    <button onclick="webcr()">WebCrypto</button>
    <pre id="pre"></pre>
</body>
</html>
 
var data = new Uint8Array(32);
var key = new Uint8Array(32);
var transformRounds = 10000;
for (var i = 0; i < 32; i++) {
  data[i] = i;
  key[i] = i + 1;
}
var now, webCrKey, webCrTimes, webCrParam, webCrData;
function webcr() {
  now = performance.now();
  webCrTimes = transformRounds;
  webCrParam = { name: 'AES-CBC', iv: new Uint8Array(16) };
  webCrData = data;
  crypto.subtle.importKey('raw', key.buffer, { name: 'AES-CBC' }, false, ['encrypt']).then(function(encKey) {
    webCrKey = encKey;
    webCrRound();
  });
}
function webCrRound() {
  crypto.subtle.encrypt(webCrParam, webCrKey, webCrData).then(webCrResult);
}
function webCrResult(encData) {
    //webCrData = encData;
    if (--webCrTimes === 0) {
      pre.innerHTML += '\nWebCrypto ' + Math.round(performance.now() - now) + 'ms: ' +
        asmCrypto.bytes_to_base64(new Uint8Array(encData));
    } else {
      webCrRound();
    }
}
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
antellepro
0viewers