Created
November 5, 2013 10:33
-
-
Save richmarr/7317039 to your computer and use it in GitHub Desktop.
Quick Node.js speed test for different crypto algorithms exposed through OpenSSL. Don't forget, speed == good but speed !== good
This file contains hidden or 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
var crypto = require('crypto'), | |
algos = crypto.getCiphers(), | |
testString = 'something to match, something to match, something to match, something to match, something to match '+algos.join("#"), | |
password = '12345asdfgh', | |
ciphertextEncoding = 'binary', | |
cleartextEncoding = 'utf8', | |
iterations = 1000; | |
algos.forEach(function( algorithm ){ | |
var start = new Date().getTime(), | |
i; | |
try { | |
for ( i = 0; i < iterations; i++ ){ | |
var cipher = crypto.createCipher( algorithm, password ); | |
var encrypted = cipher.update( testString, cleartextEncoding, ciphertextEncoding ); | |
encrypted += cipher.final( ciphertextEncoding ); | |
var decipher = crypto.createDecipher( algorithm, password ); | |
var decrypted = decipher.update( encrypted, ciphertextEncoding, cleartextEncoding ); | |
decrypted += decipher.final( cleartextEncoding ); | |
if ( decrypted !== testString ) throw new Error("match failed for "+algorithm); | |
} | |
console.log(algorithm,"did",i,"iterations in",new Date().getTime()-start,"ms"); | |
} catch(e){ | |
console.log(algorithm,e); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment